I create a 1 page PDF that contains a full page JPG image. I can open and view that PDF file with Adobe. Problem is, I cannot extract the image out of the PDF using PdfSharp.
The problem is that in the InitializeJpeg method in PdfImage, a PdfArray object is created holding two PdfName objects. PdfName("/FlateDecode") and PdfName("/DCTDecode").
In the sample code for reading an image from a PDF, the following code does not work when the /Filter key contains a PdfArray value: filter = image.Elements.GetName("/Filter");
switch (filter) { case "/DCTDecode": ExportJpegImage(image, ref count, InImagePath); break;
case "/FlateDecode": ExportAsPngImage(image, ref count, InImagePath ); break; }
I made a code change to InitializeJpeg that fixes the problem for me. The following code is always run. No matter the length of imageDataCompressed: Stream = new PdfStream(imageBits, this); Elements[Keys.Length] = new PdfInteger(streamLength); Elements[Keys.Filter] = new PdfName("/DCTDecode");
Only, I don't understand why I can't write as "/FlateDecode". The Adobe PDF reader rejects the PDF file created this way.
Thanks,
|