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);
}
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.