Convert HTML to PDF using Aspose.PDF for .NET - Saving is taking a longer than expected

Hi,

When I tried to save html to pdf, it takes almost 7 secs to save in first request, and then in subsequent request it works a bit faster.
But If I am having 100 or more html fragment, it takes to much time to save document.
Below is a sample code snippet I am using -

        Document document = new Document();
        HtmlFragment htmlFragment = new HtmlFragment("{{any html string}}");
        htmlFragment.HtmlLoadOptions = new HtmlLoadOptions();
        Page CurrentPage = document.Pages.Add();

        CurrentPage.Paragraphs.Add(htmlFragment);

        var stream = new MemoryStream();
        Console.WriteLine(DateTime.Now);

        Aspose.Pdf.Optimization.OptimizationOptions optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions
        {
            RemoveUnusedObjects = true,
            RemoveUnusedStreams = true,
            AllowReusePageContent = true,
        };
        document.OptimizeResources(optimizationOptions);

        document.Save(stream, SaveFormat.Pdf);
        Console.WriteLine(DateTime.Now);
        Console.WriteLine("completed");

And please also let me know, how to reduce the time for first request as well. I mean where I should load all the required resources as I can see that document.Save() is loading some external resources.

Thanks,
Suraj

@suraj.singh011

The performance of the API is properly calculated on subsequent runs as on the first run it loads necessary resources in the memory to process the documents. Furthermore, performance and conversion time depends upon the complexity and structure supplied HTML string. We improved performance of the API in such cases in 20.12 version.

Would you please make sure to use the latest available version. Also, please try to share a sample HTML string with us with which you are noticing the performance issue particularly so that it can be investigated accordingly.

I have been using 20.12 version and facing issue with any html string(e.g. table, paragraph tag). I have been using to add rows in table with for loop for n number of times, which is taking approx 160 secs to save into stream for first time and then in subsequent request it takes 40 secs.
Sample I have already provided above, just use any string and test inside for loop.

Any help to reduce first load time will be appreciated!

@suraj.singh011

The time taken by the first execution of the program is expected as shared in our previous comments. However, we have logged an investigation ticket as PDFNET-49216 in our issue tracking system to further analyze whether the time consumption can more be reduced or not at the first time run. We will let you know as soon as the ticket in completely investigated and resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.