Convert HTML to PDF using Aspose.HTML for .NET - Program hitting infinite loop and failing to generate PDF

Hi team,

I’m trying to generate PDF from HTML template but this conversion goes into infinite loop and pdf is not generated. I’m using Aspose html 23.5.0 and Aspose pdf 23.6.0 in our application.

We are also tried upgrading both packages to latest versions but still facing the same issue.

I’m using Aspose.Html.Converters.Converter.ConvertHTML(HTMLDocument document, PdfSaveOptions options, ICreateStreamProvider provider) method for converting html to pdf.

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 summary = await _summaryRepository.GetItemAsync(id.ToString());

string serializedJson = JsonConvert.SerializeObject(summary);

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

// Overlay data from datastore in the default template

templateDocument.GetElementById(“uwRationaleNotes”).InnerHTML = summary?.UWRationale?.Notes ?? “”;
if (summary.UWRationale.Notes == “” || summary.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 = summary?.Company;

string headerText = summary?.Company + " - " + summary?.Title + " - " + summary?.SubmissionNo;
	
AddHeaderToDocument(pdfDocument, headerText);
AddPageNumberToDocument(pdfDocument);

	pdfDocument.Save(pdfStream);


	return pdfStream.ToArray();
}




Please suggest what to do to resolve this issue.

Thank you,
Tushar Sahu

@tusharsahu

First of all, we request that you please try to use the latest available version of the API. Furthermore, if issue still persists, can you please share your sample HTML in .zip format with us? This will allow us to test the case in our environment and address it accordingly.

@asad.ali We have tried with upgraded version also but this issue still exist. Could you please check?
I’m attaching html file -
HtmlFile.zip (973.5 KB)

@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-5094

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.

Hi @asad.ali, we have analyzed further cases to reproduce the infinite loop issue. We found that if html contains below type of image, pdf conversion is failing.
HUge Image.zip (1.8 MB)

@tusharsahu

Thanks for sharing further information. We have updated the ticket information and will let you know as soon as the ticket is resolved.

@asad.ali any update on this?

@tusharsahu

Regretfully, no updates are available yet. However, your concerns are recorded and we will surely let you know once we make some progress towards ticket resolution. Please spare us some time.

We are sorry for your inconvenience.

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