Html to Tiff Conversion Throws OutOfMemory Exception

Hi Team

I had an issue with Aspose Library while converting html page into Tiff image, it throws the OutOfMemomy issue.

In my system we have enough memory i.e apto 5 GB.

These is my stack trace.

"Error Generating Invoice Tif\nSystem.OutOfMemoryException: Out of memory.\n at System.Drawing.Graphics.Save()\n at Aspose.Html.Rendering.Image.ImageDevice.SaveGraphicContext()\n at \u000f\u2006\u2003\u2002.\u0002(\u0005\u2003\u2002\u2002 \u0002, Boolean \u0003)\n at \u000f\u2006\u2003\u2002.\u0003(\u0005\u2003\u2002\u2002 \u0002, Boolean \u0003)\n at \u000f\u2006\u2003\u2002.\u0002(\u0002 \u0002, Boolean \u0003, \u0005\u2003\u2004\u2002 \u0005)\n at \u000f\u2006\u2003\u2002.\u0002(\u0006\u2005\u2002\u2002 \u0002, \u0003 \u0003, Boolean \u0005, \u0005\u2003\u2004\u2002 \b)\n at \u0006\u2000\u2006\u2001.\b\u2000\u2006\u2001\u2008\u2007\u0002(IDevice \u0002)\n at \u000e\u2003\u200a\u2001.\u0005\u2001\u200a\u2001\u2008\u2007\u0002(Renderer \u0002, \u000f\u2000\u2005\u2001[] \u0003, IDevice \u0005, TimeSpan \b)\n at Aspose.Html.Rendering.HtmlRenderer.\u0002(IDevice \u0002, TimeSpan \u0003, Element[] \u0005, Document[] \b)\n at Aspose.Html.Rendering.HtmlRenderer.Render(IDevice device, TimeSpan timeout, Document[] documents)\n at \u0005\u2003\u2006.\u0002(\b\u2003\u2006 \u0002, IDevice \u0003)\n at \u0005\u2003\u2006.\u0003\u2003\u2006\u2008\u2007\u0002(\b\u2003\u2006 \u0002, ImageSaveOptions \u0003, ICreateStreamProvider \u0005)\n

Note: This is happend only in linux environment.

@Chenchu

Are you using 23.7 version of the API? Can you please share your sample code snippet and HTML file in .zip format for our reference? We will test the scenario in our environment and address it accordingly.

Please find the sample code.
I have given custom html code.

I have used code, it’s works in my windows machine but didn’t worked hosted environment.

I have hosted my application in Linux server with the help of docker container.InvoiceTiffIssue.7z (24.7 KB)

@Chenchu

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): HTMLNET-4749

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi Team any update.
We have aspose license also.

@Chenchu

The ticket was logged recently in our issue tracking system and it will be investigated/resolved on a first come first serve basis. We have recorded your concerns and will surely inform you as soon as we make some updates in this regard. Please spare us some time.

We are sorry for the inconvenience.

@Chenchu

We tested the provided code in linux docker and couldn’t reproduce the OutOfMemoryException. Could you share what version of Linux you are using?

Also, when analyzing the provided code and the stack trace, we noticed that the exception occurred at the time of saving to BMP. This format does not compress the image and therefore takes up a lot of space, which is most likely what caused the exception. Could you please use Aspose.Html.Rendering.Image.ImageFormat.Jpeg as an intermediate format? It will take 193 times less memory space and will most likely fix the problem. Here is a code snippet showing how to do it:

private static void CreateBitmap(HTMLDocument document, Stream destination)
{
    ImageSaveOptions saveOptions = new ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg);
    Converter.ConvertHTML(document, saveOptions, new ExistingStreamAdapter(destination));
}

Hi @asad.ali
Thanks for the quick replay, As you suggested, I have tried with jpeg no luck getting the same issue again.
image.png (33.9 KB)

Are you using the same html file which I have shared and one more thing I am using Aspose.Html 23.6
Regarding Linux I am using Redhat(RHEL)

A post was split to a new topic: I am getting the Out of memory Exception when trying to convert HTML to tiff image in Linux environment

@Chenchu

We tested using 23.7 version of the API. Can you please try using the latest version and let us know about the results you got? We will further proceed accordingly.