PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Bitonal (1bpp) Tiff to PDF
http://forum.pdfsharp.com/viewtopic.php?f=2&t=1282
Page 1 of 1

Author:  jknipp [ Thu Jul 29, 2010 6:04 pm ]
Post subject:  Bitonal (1bpp) Tiff to PDF

I am trying to convert scanned images converted to a Bitonal (1bpp) Tiff to a PDF document. The conversion process from 32bppARGB to 1bbp Indexed format (Bitonal) tiff with CCITT4 compression appears to work smoothly as I am able to view the file and convert it to pdf using a 3rd party tool.

The document creation process also appears to work fine, however, when I open the newly created PDF document, I receive an "Insufficient data for an image" error message from adobe.

I could revert to using the 32bpp file, but it is an order of magnitude slower to create the Pdf document per image/page scanned. Any suggestions are welcome.

Code to create Pdf document
Code:
        public static PdfDocument CreatePdfFromTiffs(List<string> tiffList)
        {
            PdfDocument doc = new PdfDocument();

            tiffList.ForEach(img =>
            {
                if (string.IsNullOrWhiteSpace(img)) throw new ArgumentNullException("path");

                if (File.Exists(img))
                {
                    PdfPage page = doc.AddPage();

                    using (XGraphics gfx = XGraphics.FromPdfPage(page))
                    {
                        DrawTiff(gfx, 1, img, ref page);
                    }
                }
            });
        }


        public static void DrawTiff(XGraphics gfx, int number, string tiffSamplePath, ref PdfSharp.Pdf.PdfPage page)
        {
            using (XImage image = XImage.FromFile(tiffSamplePath))
            {
                // Make the page the same size as the tiff image that
                // was scanned.
                page.Height = XUnit.FromPoint(image.Size.Height);
                page.Width = XUnit.FromPoint(image.Size.Width);

                gfx.DrawImage(image, 0, 0, image.Size.Width, image.Size.Height);
            }
        }

Author:  () => true [ Thu Jul 29, 2010 7:32 pm ]
Post subject:  Re: Bitonal (1bpp) Tiff to PDF

Not much we can do without a sample picture.
And it'll have to wait until after the company holidays.

PDFsharp 1.31 supports CCITT compression and will use it for bilevel images if filesize is smaller than with LZW compression.
PDFsharp 1.30 doesn't support CCITT compression; if you think the problem is with CCITT compression then revert to version 1.30.

If you have PDFsharp, only LZW images will be embedded into the PDF - even if you draw CCITT compressed images.

You can try using 4bpp images with black and white only. This forces LZW compression even with PDFsharp 1.31 (could be a workaround if you don't want to revert).

Author:  jknipp [ Thu Jul 29, 2010 9:01 pm ]
Post subject:  Re: Bitonal (1bpp) Tiff to PDF

The issue occurs when using the PDFSharp-WPF 1.31 library.

I switched to using the GDI+ version of PDFSharp 1.31 and was able to create the PDF just fine from my 1bbp Tiff. I've attached a sample image that I was using for testing purposes. Hope that helps.

Attachments:
File comment: Test file
tmp.tiff
tmp.tiff [ 2.34 KiB | Viewed 4836 times ]

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/