PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 4:14 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
 Post subject: Extract TIF from PDF
PostPosted: Wed Feb 25, 2009 2:02 pm 
Offline

Joined: Wed Feb 25, 2009 1:50 pm
Posts: 2
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?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 02, 2009 10:08 am 
Offline

Joined: Wed Feb 25, 2009 1:50 pm
Posts: 2
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?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 02, 2009 4:24 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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/develo ... ence16.pdf

_________________
Regards
Thomas Hoevel
PDFsharp Team


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 330 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