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

Free Support Forum - aspose.com

Performance of XML with HtmlFragment conversion to PDF

Hi,

We are looking for a fast way to convert HTML to PDF. We find XML to PDF conversion very convenient and we tried the HtmlFragment tag in order to accomplish this.

Here is a simple sandbox app we are using that is measuring the conversion time XmlToPdfPerformance.zip (4.2 KB)

Unfortunately the performance is bad: it takes ~4 seconds to create a PDF with a simple HTML div tag inside.

Is this something that you are aware of?
Moreover, is there any fast approach to converting HTML to PDF?

Thank you!

@gwert

Thank you for contacting support.

We have worked with the data shared by you with Aspose.PDF for .NET 18.7, and have made few modifications for further performance testing. We have made 15 iterations in a loop and have noticed that first iteration takes around 6 seconds and then 6 iterations in next second, and again 6 files for the next second. Thus around 9 seconds for 15 iterations in total.

First iteration takes more time span as compared to others because whole Document Object Model (DOM) of Aspose.PDF for .NET API is loaded into memory and other necessary resources are allocated. We hope this addresses your performance concerns. Please feel free to contact us if you need any further assistance.

Hi,

I confirm it and it we can work with it if we can find a way to trigger DOM loading into memory in a more elegant way than doing a dummy conversion.

So is there one call to the API that would directly/indirectly trigger DOM loading into memory?

Thank you!

@gwert

Please note that you can load DOM into memory by instantiating Document constructor and then follow with your application process. We hope this will be helpful, feel free to contact us if you need any further assistance.

Hi,

That you for getting back on this one!
I have tried the suggested workaround but did not work.

Only doing an actual conversion (e.g. actually saving it in a stream) will force DOM loading in memory.

Code:

            using (var outputStream = new MemoryStream())
            {
                var d = new Document();
                d.BindXml("path_to_XML_file");
                d.Save(outputStream);
            }

Is there any other ways that I could force DOM to be loaded in memory? If it’s an async one then even better.

Best regards!

@gwert

We have logged an investigation ticket with ID PDFNET-45196 in our issue management system and will share our further findings with you once the issue is analyzed in our environment. We appreciate your patience and comprehension in this regard.