PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Sep 27, 2024 11:28 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Jul 29, 2010 6:04 pm 
Offline

Joined: Thu Jul 29, 2010 5:08 pm
Posts: 2
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);
            }
        }


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 29, 2010 7:32 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 345
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).

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 29, 2010 9:01 pm 
Offline

Joined: Thu Jul 29, 2010 5:08 pm
Posts: 2
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 4827 times ]
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 59 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group