PDF generation is taking more then 10 seconds

Hi team,
I’m trying to generate PDF from HTML template but it is taking more then 10 seconds to generate the pdf document.
I’m using Aspose.Html.Converters.Converter.ConvertHTML(HTMLDocument document, PdfSaveOptions options, ICreateStreamProvider provider) method for converting html to pdf.

Please suggest what to do to resolve this issue.

Thank you,
Tushar Sahu

@tusharsahu

Would you please share your sample HTML template for our reference as well? You can attached it in ZIP format and we will further proceed to assist you accordingly.

HTML_File.zip (5.4 MB)

@asad.ali
We are fetching data from external source and replacing values in template. Now we are converting html template to aspose template and then converting to pdf.
below is the small portion of our code -

//Fetching data
var uwSummary = await _uwSummaryRepository.GetItemAsync(id.ToString());

string serializedJson = JsonConvert.SerializeObject(uwSummary);

// Setup default template with placeholders(only a portion of code)
string documentPath = Path.Combine(templatePath, “uwsummarytemplate.html”);
HTMLDocument templateDocument = new HTMLDocument(documentPath);
templateDocument.Title = uwSummary?.CedingCompany;

// Overlay data from datastore in the default template

//UW Rationale
templateDocument.GetElementById(“uwRationaleNotes”).InnerHTML = uwSummary?.UWRationale?.Notes ?? “”;
if (uwSummary.UWRationale.Notes == “” || uwSummary.UWRationale.Notes == null)
{
templateDocument.GetElementById(“uwRationale”).SetAttribute(“style”, “display:none”);
}

//After preparing template, below is the code for pdf generation. This portion is taking more than 10 seconds for conversion.

// Setup Template Options with Serialized json from repository
TemplateContentOptions templateOptions = new TemplateContentOptions(serializedJson, TemplateContent.JSON);
using (var streamProvider = new MemoryStreamProvider())
{
// Initialize HTML Template Merge
using (var mergedTemplate = Converter.ConvertTemplate(templateDocument, new TemplateData(templateOptions), new TemplateLoadOptions()))
{
// Convert HTML to PDF and load output to MemoryStreamProvider
Aspose.Html.Converters.Converter.ConvertHTML(mergedTemplate, new Aspose.Html.Saving.PdfSaveOptions(), streamProvider); //This conversion is taking more than 10 sec.Also more then 30 sec in some cases.

	// Get access to the memory stream that contains the result data
	var pdfStream = streamProvider.Streams.First();
	pdfStream.Seek(0, System.IO.SeekOrigin.Begin);

Document pdfDocument = new Document(pdfStream);
PdfFileInfo pfi = new PdfFileInfo(pdfDocument);
pfi.Title = uwSummary?.CedingCompany;

string headerText = uwSummary?.CedingCompany + " - " + uwSummary?.TreatyTitle + " - " + uwSummary?.SubmissionNo;
	
AddHeaderToDocument(pdfDocument, headerText);
AddPageNumberToDocument(pdfDocument);

	pdfDocument.Save(pdfStream);

	DateTime pdfGenerationEndTime = DateTime.Now;
	TimeSpan pdfGenerationElapsedTime = pdfGenerationEndTime - pdfGenerationStartTime;
	_logger.LogInformation("ReferralIntegrationController.UpdateAssociatedReferrals.GeneratePdfDocument: pdfGenerationLogic ended at : {pdfGenerationEndTime} Elapsed Time : {pdfGenerationElapsedTime} seconds for Id: {id}", pdfGenerationEndTime, pdfGenerationElapsedTime.Seconds, id);

	return pdfStream.ToArray();
}

}

@tusharsahu

Thanks for sharing the sample HTML. We have already been working on performance of the API and hopefully in the next release, the API performance will be improved. If its possible, can you please also share the output PDF that has been generated at your end from this HTML file?

@asad.ali

Attached PDF file also. Could you please confirm the date of release?
Preview.zip (9.6 MB)

@tusharsahu

We already published 23.10 version of the API in which performance is improved. More improvements will be part of 23.11 version which will be published next month i.e. November 2023. Can you please try with 23.10 version and let us know if conversion time is better at your end? Please also share your environment details like OS Name and Version, installed RAM, etc.

@asad.ali
I’ve tried with 23.10 version but did not see much improvements.

@tusharsahu

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): HTMLNET-5065

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@asad.ali Any update on this?

@tusharsahu

We are afraid that the earlier logged ticket has not been yet resolved due to other issues in the queue. We will surely inform you once we have some news about its resolution or fix ETA. We are sorry for the inconvenience.

@asad.ali Could you please try to expedite. we have total license.

@tusharsahu

In the free support model, the issues are prioritized on first come first serve basis. Nevertheless, we have recorded your concerns and escalated the ticket to the next level of priority. As soon as we make some progress, we will surely inform you. Please spare us some time.

@tusharsahu

We have optimized the processing of images when converting to PDF and these changes will be included in release 24.2. On the test document, the conversion was accelerated 4 times.

@asad.ali Can you explain in which method the image processing is improved, whether it’s in Aspose.Html.Converters.Converter.ConvertHTML() method or in new Aspose.Pdf.Document(htmlStrStream, options)?
We are expecting performance improvement & acceleration in Aspose.Pdf.Document(htmlStrStream, options) method.

@tusharsahu

Please allow us to gather more details. We have updated the ticket information and will let you know as soon as we have some updates.

Hi @asad.ali,
any updates on this comment?

Can you explain in which method the image processing is improved, whether it’s in Aspose.Html.Converters.Converter.ConvertHTML() method or in new Aspose.Pdf.Document(htmlStrStream, options)?
We are expecting performance improvement & acceleration in Aspose.Pdf.Document(htmlStrStream, options) method.

@tusharsahu

We have significantly accelerated processing in the Aspose.Html.Converters.Converter.ConvertHTML() method. The Aspose.PDF.Document(html Stream, options) method refers to the Aspose.PDF product. In case you have concerns with Aspose.PDF API, please do share so that we can investigate accordingly.

Hi @asad.ali,
We have concerns & slowness issues with mainly Aspose.PDF api. It’s taking lot off time to convert HTML to PDF for smaller size pages also. We even tried upgrading it to latest release 24.2.0, but still facing same slowness issues.

The issues you have found earlier (filed as HTMLNET-5065) have been fixed in this update. This message was posted using Bugs notification tool by avpavlysh

@tusharsahu

Can you please share the sample files and the code snippet for our reference so that we can investigate and further proceed accordingly?