HTML to PDF too slow with version 25.7.0 and above

Dear support team,

We are using Aspose.pdf version 25.7.0 for html to pdf
Below is the code that we are using for HTML to PDF where “using (Document pdfDocument = new Document(stream, htmloptions))” is taking too much time to load the doc, this is working fine till 25.6.0 but not beyond that. I’ve tried 25.10 as well. Below is the code for your reference and attached the HTML file as well.

var htmloptions = new Aspose.Pdf.HtmlLoadOptions();
htmloptions.CustomLoaderOfExternalResources = resource => null;
htmloptions.PageInfo = new PageInfo() { Margin = new MarginInfo(0, 20, 0, 20) };

using (var stream = new MemoryStream(htmlContent))
{
    using (MemoryStream outputSteam = new MemoryStream())
    {
        // NOTE ::: BELOW LINE IS TAKING TOO MUCH TIME TO LOAD the document...
        using (Document pdfDocument = new Document(stream, htmloptions))
        {

        }
     }
}

please go through the same and let me know your feedback for the same

SampleResume.zip (23.6 KB)

@amitmalhotra

Summary
Starting with Aspose.PDF v25.7 the HTML‑to‑PDF conversion uses a newer rendering engine that, by default, parses CSS, executes JavaScript and tries to load external resources. Those extra steps can add noticeable latency, especially when the source HTML is simple and those features are not required.

Why it happens

  1. New default rendering engine – From v25.7 the engine is based on Aspose.HTML (WebKit). It performs full layout, script execution and resource fetching unless the corresponding options are turned off.
  2. External‑resource scanning – Even when a custom loader returns null, the engine still scans the markup for <link>, <script> and <img> tags, which adds processing time.
  3. Stream position – If the same MemoryStream is reused, its Position may be at the end after a previous write, causing the Document constructor to read an empty stream and then re‑process, which further slows the operation.

What to do next

  1. Reset the input stream before loading
using (var htmlStream = new MemoryStream(htmlBytes))
{
htmlStream.Position = 0; // ensure reading starts at the beginning
// …
}
  1. Disable unneeded features via HtmlLoadOptions
var htmlOptions = new Aspose.Pdf.HtmlLoadOptions
{
// Prevent the engine from trying to download external files
EnableExternalResources = false, // introduced in v25.7

// Skip JavaScript execution if it is not required
EnableJavaScript = false,

// Omit CSS parsing when the layout is simple
EnableCss = false,

// Keep your existing page settings
PageInfo = new PageInfo
{
Margin = new MarginInfo(0, 20, 0, 20)
}
};
  1. Choose the rendering engine that best fits your performance needs
// Use the legacy engine (the one that was the default before v25.7)
htmlOptions.HtmlRenderingEngine = HtmlRenderingEngine.Browser;

// Or keep the newer engine but with the reduced‑work settings above
// htmlOptions.HtmlRenderingEngine = HtmlRenderingEngine.WebKit;
  1. Load the document and save the PDF
using (var pdfStream = new MemoryStream())
{
using (var pdfDoc = new Document(htmlStream, htmlOptions))
{
pdfDoc.Save(pdfStream);
}
}
  1. If the conversion is still slower than expected, consider using Aspose.HTML directly – Aspose.HTML provides a dedicated HtmlToPdfConverter that is optimized for high‑speed conversions. Example:
using Aspose.Html;
using Aspose.Html.Converters;
using Aspose.Html.Rendering.Pdf;

var converter = new HtmlToPdfConverter();
var pdfSaveOptions = new PdfSaveOptions(); // configure page size, margins, etc. if needed
converter.Convert(htmlStream, pdfSaveOptions, pdfStream);
  1. Measure the impact
  • Wrap the conversion code with a Stopwatch to record elapsed time before and after applying the changes.
  • Compare the results with the same HTML on v25.6 (if available) to confirm the performance gain.

If, after applying the steps above, the latency remains excessive, please provide the size of the HTML payload and any external assets it references. We will investigate further internally and determine whether additional tuning or a hot‑fix is required.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

Thanks for your quick response! however I am not getting EnableExternalResources, EnableJavaScript, EnableCss and HtmlRenderingEngine properties in .net nuget package version 25.7.0 ,25.8.0, 25.9.0 and 25.10.0 . Attached is the image for properties that we are getting for Aspose pdf html options.
image.png (47.3 KB)

@amitmalhotra

We apologize for the confusion. Please note that the above response was AI generated and please feel free to disregard it. We are constantly working on improving the quality.

Nevertheless, we have logged an investigation ticket as PDFNET-61217 to further analyze your case. We will look into the details of this ticket and let you know as soon as it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.