View previous topic :: View next topic |
Author |
Message |
Banjo
Joined: 25 Feb 2009 Posts: 2
|
Posted: Wed Feb 25, 2009 2:02 pm Post subject: Extract TIF from PDF |
|
|
Hi guys,
We have a PDF file that contains embedded tif images. We need to extract these and save them back into a tif file.
We have it narrowed down to the image element passed to this function:
Code: | static void ExportImage(PdfDictionary image, ref int count)
{
string filter = image.Elements.GetName("/Filter");
switch (filter)
{
case "/DCTDecode":
ExportJpegImage(image, ref count);
break;
case "/FlateDecode":
ExportAsTifImage(image, ref count);
break;
}
} |
The ExportJpegImage function works fine using a BinaryWriter object to dump the jpeg file out. This is what I currently have for the Tif function:
Code: | static void ExportAsPngImage(PdfDictionary image, ref int count)
{
int width = image.Elements.GetInteger(PdfImage.Keys.Width);
int height = image.Elements.GetInteger(PdfImage.Keys.Height);
int bitsPerComponent = image.Elements.GetInteger(PdfImage.Keys.BitsPerComponent);
byte[] stream = image.Stream.Value;
MemoryStream memStream = new MemoryStream(stream, 0, stream.Length, true, true);
Bitmap MyBitmap = new Bitmap(memStream, true);
MyBitmap.Save("C:\\temp\\texttographic.tif", System.Drawing.Imaging.ImageFormat.Tiff);
} |
This fails trying to create the bitmap object. System.ArgumentException is thrown with additional information of "Invalid Parameter Used".
Can anyone advise on how to save out tifs? Am I on even vaguely the right track? |
|
Back to top |
|
|
Banjo
Joined: 25 Feb 2009 Posts: 2
|
Posted: Mon Mar 02, 2009 10:08 am Post subject: |
|
|
ok, I've found the stuff in the samples that says there's a custom internal format that would need to be worked with to export the tiff image.
Is there anywhere that details this format? |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Mon Mar 02, 2009 4:24 pm Post subject: |
|
|
PDFsharp contains code that creates the PDF format from GDI+ images.
See "void InitializeNonJpeg()" in PdfImage.cs.
See the Adobe PDF documentation for all details.
Here's one for Acrobat 7 (9 MB approx.):
http://partners.adobe.com/public/developer/en/pdf/PDFReference16.pdf _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
|