Out Of Memory error with HTML to PDF

I have been getting Out Of Memory errors when creating the PDF documents from HTML. I originally experienced the problem in Aspose 10, but was told to test in 10.4, which I did. I’m still getting the same error in 10.4


I’ve highlighted the line of code causing the problem. As a side note, I’ve also tried this by creating multiple pages and then putting those pages together into a new PDF. Both approaches fail with the same problem.

I’ve also attached the html file that’s causing the problem.

public void CreatePdfFromHtml(string anHtml, string anImageUrl, string aDestinationPath, bool isLandscape = true, bool includePageNumbers = true)
{

Pdf pdf = new Pdf {HtmlInfo = {ImgUrl = anImageUrl}};

Section section = pdf.Sections.Add();
section.IsLandscape = isLandscape;

Text text = new Text(section, anHtml);
text.IsHtmlTagSupported = true;

// Add page margins
Aspose.Pdf.Generator.MarginInfo marginInfo =
new Aspose.Pdf.Generator.MarginInfo
{
Top = PDF_MARGIN_TOP,
Bottom = PDF_MARGIN_BOTTOM,
Left = PDF_MARGIN_LEFT,
Right = PDF_MARGIN_RIGHT
};
section.PageInfo.Margin = marginInfo;
section.Paragraphs.Add(text);
Document document = new Document(pdf);

// Add page numbering
if(includePageNumbers)
{
PdfFileStamp pdfFileStamp = new PdfFileStamp(document);
FormattedText formattedText = new FormattedText(string.Format(" page # of {0}", pdf.PageCount));
pdfFileStamp.StartingNumber = 1;
pdfFileStamp.AddPageNumber(formattedText, 5);
}
document.Save(aDestinationPath);
}

Update: I’ve modified the method above to read as follows, per instructions found here http://www.aspose.com/docs/display/pdfnet/Convert+HTML+to+PDF+Format:

public void CreatePdfFromHtml(string anHtml, string anImageUrl, string aDestinationPath, bool isLandscape = true, bool includePageNumbers = true)
{
HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();

htmlLoadOptions.PageInfo.Margin.Top = PDF_MARGIN_TOP;
htmlLoadOptions.PageInfo.Margin.Left = PDF_MARGIN_LEFT;
htmlLoadOptions.PageInfo.Margin.Right = PDF_MARGIN_RIGHT;
htmlLoadOptions.PageInfo.Margin.Bottom = PDF_MARGIN_BOTTOM;
htmlLoadOptions.PageInfo.IsLandscape = isLandscape;
htmlLoadOptions.PageInfo.Height = 11;
htmlLoadOptions.PageInfo.Width = 8.5;
Document document =
new Document(new MemoryStream(Encoding.UTF8.GetBytes(anHtml)), htmlLoadOptions);

document.Save(aDestinationPath);
}

This time the processing took about an hour and resulted in the exact same error.

Hi Denis,

Thanks for your inquiry. I have tested your scenario with shared HTML using Aspose.Pdf for .NET 10.4.0 and managed to observe the reported exception. For further investigation, I have logged an issue in our issue tracking system as PDFNEWNET-38717 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

Please feel free to contact us for any further assistance.

Best Regards

Is there any update on this?

Hi Denis,


Thanks for your patience.

I am afraid the requested feature is still pending for review as the team has been busy fixing other previously reported issues. As soon as we have some further updates regarding its resolution, we will let you know.

The issues you have found earlier (filed as PDFNET-38717) have been fixed in Aspose.PDF for .NET 23.6.