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?