Free Support Forum - aspose.com

Still can't convert PDF's to images

Hi All,

First, I’m working in a .Net 3.5, VS2008, web application. I’ve just downloaded the latest Aspose hot fix Aspose.Pdf.Kit.4.5.0.1.Hotfix.zip, removed the previous Kit dll’s from my project, and added the new 3.5 ones. I also have the Aspose.Pdf dll, but I don’t know if I need the latest of that too.

Second, I’m trying to load an asp:Image control by setting ImageUrl to a httpHandler page.

On the httpHandler page I have the following code:

Bitmap bmp = null;
PdfConverter convPDF = null;
MemoryStream ms = null;

try
{
convPDF = new PdfConverter();
convPDF.BindPdf(sPath);
convPDF.DoConvert();
ms = new MemoryStream();

convPDF.StartPage = 1;
convPDF.EndPage = 1;

while (convPDF.HasNextImage())
{
convPDF.GetNextImage(ms, System.Drawing.Imaging.ImageFormat.Bmp);
bmp = (Bitmap)System.Drawing.Image.FromStream(ms);
}
etc.

The first issue is that the DoConvert() command is taking about 15 seconds to complete on a file that’s only 90 KB. I can’t imagine how it’ll behave on larger files. I have one that’s 1048 KB.

The second issue is that on the GetNextImage line I’m getting an “Out of Memory” error right away.

I can email the pdf privately, but not publicly.

Thanks!!!
Larry

I’ve just noticed that some PDF’s work, while others don’t. I can open all of them in Adobe Reader immediately. Maybe writing the PDF’s to an iframe or something is more reliable?

Hi Larry,

You can use the ‘Contact -> Send shahzad.latif an email’ option at the top of this post. Moreover, I would like to share with you that due to the particular contents or origin of the PDF files, sometimes this kind of issue might occur. Otherwise, we have processed a lot bigger files without any issues. Please send the problematic PDF file(s), so we could test the issue at our end.

We’re sorry for the inconvenience.
Regards,

This seems to work a little better if I just leave out the HasNextImage, where intPage is the desired page:

convPDF = new PdfConverter();
convPDF.BindPdf(sPath);
convPDF.DoConvert();
ms = new MemoryStream();

convPDF.StartPage = intPage;
convPDF.EndPage = intPage;

convPDF.GetNextImage(ms, System.Drawing.Imaging.ImageFormat.Bmp);
bmp = (Bitmap)System.Drawing.Image.FromStream(ms);

At least this way I don’t have to worry about HasNextImage hanging like it used to. But, what do I lose by doing this?

Hi Larry,

I have tested this file at my end using the latest hot fix. I have noticed that although the processing time is not reduced in this fix, it doesn’t hang and the out of memory exception doesn’t occur at HasNextImage method. As far as processing time is concerned, I have logged this issue as PDFKITNET-17987 in our issue tracking system. Our team will investigate it in detail and you’ll be updated via this forum thread once the performance is improved.

Moreover, I would like to share with you that HasNextImage method allows you to check whether there are more pages to process or not. You can use this with if condition or while loop; it helps you avoid any exceptions in case there are no further pages. It also helps you move to the next page when processing all the pages of the PDF files.

We’re sorry for the inconvenience. If you have any further questions, please do let us know.
Regards,

The issues you have found earlier (filed as 17987) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

This actually seems to have made it worse, unless I'm doing something wrong. I downloaded the update, ran it, and replaced my bin\Aspose.pdf.kit.dll with the new one in

C:\Program Files\Aspose\Aspose.Pdf.Kit for .Net\bin\net3.5.

One thing I noticed is that while the modified date is more recent - 7/30/2010 as opposed to 6/11/2010, the new file was smaller in size than the old one - 9K as opposed to 10K.

In any case, now I get an Out of Memory error on the following line:

convPDF.DoConvert();

Instead of on the HasNextImage line.- it never gets that far. Please tell me I didn't update coreectly!

Thanks,

Larry

Hi Larry,

First of all, please go through the following steps:

1) Remove any existing reference to the Aspose.Pdf.Kit DLL
2) Build the project with out adding any new reference
3) Add reference to the new DLL (4.7.0)
4) Build the project and Execute

Secondly, I have noticed that the file you’re having problem with at the moment is different than the one you shared already. I would like to share with you that sometimes it is not just the size of the file which causes memory to spike, or cause out of memory exception, rather the internal structure of the PDF file might cause this as well, in spite of having small size. So, if you still find the same issue, after going through the above steps, then please share the problematic PDF file with us, so we could test it at our end.

Also, please make sure that you also set the following ForeceTiffProcessing property of the PdfConverter object before DoConvert method:


ForceTiffProcessing = TiffProcessingMode.Complete

We're sorry for the inconvenience and looking forward to help you out.
Regards,

Hello - I think the ForceTiffProcessing did the trick! Before I saw that, I followed your steps and still got the out of memory error, but back on the GetNextImage method. Then I saw your ForceTiffProcessing suggestion (it didn't show up in my email, only online) and now I'm seeing the PDF.

Thank you very much for your time and patience!