PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Problem extracting image that was earlier written to PDF doc https://forum.pdfsharp.net/viewtopic.php?f=2&t=1053 |
Page 1 of 1 |
Author: | SteveRichter [ Thu Feb 11, 2010 11:24 pm ] |
Post subject: | Problem extracting image that was earlier written to PDF doc |
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, |
Author: | Thomas Hoevel [ Tue Feb 16, 2010 10:43 am ] |
Post subject: | Re: Problem extracting image that was earlier written to PDF doc |
The Export Images sample is not prepared for images that are compressed twice. In your case you must call the FlateDecoder to get a JPEG file. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |