Issue Converting HTML to PDF using Aspose.PDF - C# API

Hi Aspose Team,

We are trying to convert a HTML file to PDF using Aspose.PDF using the code snippet mentioned here. Convert HTML to PDF in C# .NET | Export URL or HTML File to PDF | Aspose

A PDF file is being generated but with HTML content and not being converted example Tables and images are being displayed in HTML text.ABC.pdf (100.1 KB)

Can you please help us know why pdf is not working / rendering correctly.

Thanks

@adityav

We have tested the scenario using the following code example and have not found the shared issue. So, please use following code example to convert HTML to PDF.

// Create HTML load options
HtmlLoadOptions htmloptions = new HtmlLoadOptions();
// Load HTML file
Document doc = new Document(MyDir + "input.html", htmloptions);
doc.Save(MyDir + "22.1.pdf");

For more detail, please read the following article.
Convert HTML to PDF file

Hi @tahir.manzoor,

Thanks for the reply. QQ - Should the name of the html and pdf always be hardcoded strings or can we get/set the name of the html or pdf at run time .

I’m running this code.

// Create HTML load options
HtmlLoadOptions htmloptions = new HtmlLoadOptions();
// Load HTML file
Document doc = new Document(htmlDir + htmlfileName, htmloptions);
doc.Save(pdfDir + pdfFileName);

where we htmlFileName and “pdfFileName” are evaluated at run time which will have vales “.html” and “.pdf” . When trying this I’m generating the PDF with html syntax as attached.ABC.pdf (100.1 KB)

@adityav

You can change the file names at run time. However, the path of input HTML document should be correct. Please create a Visual Studio application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.