I am using a C# FreeImage wrapper. I am trying to open a PDF file containing images, and "extract" those images into windows Bitmap objects. I am following the guidelines described in articles on the internet, following loosely the following pattern:
byte[] bytes = GetPdfFile();
iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(bytes);
int pageNumber = 0;
for (int i = 0; i <= reader.XrefSize - 1; i++)
{
pdfObj = reader.GetPdfObject(i);
if ((pdfObj != null) && pdfObj.IsStream())
{
pdfStream = (iTextSharp.text.pdf.PdfStream)pdfObj;
iTextSharp.text.pdf.PdfObject subtype = pdfStream.Get(iTextSharp.text.pdf.PdfName.SUBTYPE);
if ((subtype != null) && subtype.ToString().Equals(iTextSharp.text.pdf.PdfName.IMAGE.ToString()))
{
pageNumber++;
byte[] imgBytes = iTextSharp.text.pdf.PdfReader.GetStreamBytesRaw((iTextSharp.text.pdf.PRStream)pdfStream);
if ((imgBytes != null))
{
// in my case images are in TIF Group 4 format
using (MemoryStream ms = new MemoryStream(imgBytes))
{
FreeImageAPI.FIBITMAP bmp = FreeImageAPI.FreeImage.LoadFromStream(ms);
// in my case bmp with IsNull = true is returned
if (!bmp.IsNull)
{
using (MemoryStream msOut = new MemoryStream())
{
FreeImageAPI.FreeImage.SaveToStream(bmp, msOut, ... ); // etc.
}
}
}
}
}
}
}
Does anybody have a suggestion on how to troubleshoot this, given that no exception is returned - some kind of GetLastError FreeImage function? Thank you