Free Support Forum -

Object reference not set to an instance of an object | conversion html to pdf

There is a “Object reference not set to an instance of an object” error when converting attached html file.


// .pdf
MemoryStream dstStream = new MemoryStream();
Html.Rendering.Pdf.PdfRenderingOptions pdf_options = new Html.Rendering.Pdf.PdfRenderingOptions();
using (Html.Rendering.Pdf.PdfDevice pdf_device = new Html.Rendering.Pdf.PdfDevice(pdf_options, dstStream))
using (Html.Rendering.HtmlRenderer renderer = new Html.Rendering.HtmlRenderer())
using (Html.HTMLDocument html_document = new Html.HTMLDocument(stream, “”))
renderer.Render(pdf_device, html_document);
dstStream.Position = 0;
string outputPath = Path.Combine(outputRootPath, Path.GetFileNameWithoutExtension(path) + " " + DateTime.Now.Ticks.ToString() + “.pdf”);
using (FileStream fs = new FileStream(outputPath, FileMode.CreateNew, FileAccess.Write))
stream.Position = 0; (2.7 KB)


Thank you for contacting support.

We have worked with the data shared by you but the issue is not being reproduced in our environment. We have attached generated PDF file for your kind reference Test.pdf. Please try using Aspose.HTML for .NET 18.4 in your environment and then share your kind feedback with us.

Works perfectly with new components. Thanks.