We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting HTML to PDF file getting memory out of exception

Hi,

Our HTML file has more number of pages around 100 pages, I’m trying to convert HTML to PDF file getting memory out of exception, please give me a solution to resolve this issue.

Please find below snippet code

System.Text.StringBuilder htmlContentPDF = new System.Text.StringBuilder();
string linePDF;
using (System.IO.StreamReader htmlReaderPDF = new System.IO.StreamReader(@“F:/eVReports-ca-23_07_2018_01_28_47.html”))
{
while ((linePDF = htmlReaderPDF.ReadLine()) != null)
htmlContentPDF.Append(linePDF);
}

MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(htmlContentPDF.ToString()));

HtmlLoadOptions options = new HtmlLoadOptions();
options.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
options.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;
options.PageInfo.Margin.Left = 10;
options.PageInfo.Margin.Right = 10;
options.PageInfo.Margin.Top = 10;
options.PageInfo.Margin.Bottom = 10;

Document pdfDocument = new Document(stream, options);

Thanks,

@kranthireddyr

Thank you for contacting support.

Would you please share the source HTML file with us by uploading it to Google Drive, Dropbox etc, and mention your environment details (OS details, .NET Framework version, Installed memory size etc) so that we may try to reproduce and investigate it in our environment. Before sharing requested data, please ensure using Aspose.PDF for .NET 18.7 in your environment.

Furthermore, your code snippet includes loading of source file and there is not any Save method call. Therefore, please specify if the exception occurs while loading the source file or while saving it as PDF so that we may proceed to help you out.