Here is the code we’re using for converting HTML to PDF.
public static byte[] ConvertHtmlToPdfWithPageSize(string html, float leftMargin, float rightMargin,
float topMargin, float bottomMargin, float footerHeight, float pageWidth, float pageHeight, bool paginator, string pageFooter,
HorizontalPlacement pageNumberAlignment)
{
byte[] results = new byte[] { };
pageWidth = new Unit(UnitMetric.Inch, pageWidth).ValueInPoint;
pageHeight = new Unit(UnitMetric.Inch, pageHeight).ValueInPoint;
leftMargin = new Unit(UnitMetric.Inch, leftMargin).ValueInPoint;
topMargin = new Unit(UnitMetric.Inch, topMargin).ValueInPoint;
rightMargin = new Unit(UnitMetric.Inch, rightMargin).ValueInPoint;
bottomMargin = new Unit(UnitMetric.Inch, bottomMargin).ValueInPoint;
footerHeight = new Unit(UnitMetric.Inch, footerHeight).ValueInPoint;
DocumentManagementMethods.SetLicensePdf();
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(html ?? "")))
{
using (Document document = new Document(stream, new HtmlLoadOptions()
{
PageInfo = new PageInfo()
{
Width = pageWidth,
Height = pageHeight,
Margin = new MarginInfo(leftMargin, bottomMargin, rightMargin, topMargin)
}
}))
{
document.Flatten();
// Add footer on all pages
foreach (Page page in document.Pages)
{
using (page)
{
AddFooterToPage(page, document, pageFooter, paginator, pageNumberAlignment, pageHeight, leftMargin, rightMargin, footerHeight);
}
}
using (MemoryStream ms = new MemoryStream())
{
document.Save(ms, SaveFormat.Pdf);
results = ms.GetBuffer();
}
}
}
//Force garbage collecting.
GC.Collect();
return results;
}
We are experiencing fast memory growth that consumes all the memory on the server and crashes the process. Upon review of the crash dump, the memory is filled with Aspose objects but the class names are obfuscated so I cannot confirm exactly which objects are leaking.
Any help is appreciated!