HTML insertion in PDF issue

Hi,

We are trying to convert HTML to PDF using HTMLLoadOptions.
The HTML contains images to be displayed in the PDF.

We have tried to use relative path in the HTML and specifying the base-path in HTMLLOadOptions.
Along with that we also tried to insert HTML using the entire path of the image(basepath+relativePath) in HTML.
In both of the above cases the image is not getting displayed in the generated PDF.

The same HTML(having the absolute path of the image) when saved in the local system displays the image correctly when viewed in any browser.

Please provide the resolution of the issue.

PFA the java code for your reference.
The Generated PDF file and the screenshot of the HTML file on the browser is also attached.

The Aspose PDF version that we are using is 11.5.0.0

Thanks

Hi Robert,

Thanks for your inquiry. I have tested the scenario with Aspose.Pdf for Java 17.1.0 and unable to notice the reported issue. Please download and try latest version of Aspose.Pdf for Java as following it will resolve the issue.

Furthermore, please note we pass basePath to HtmlLoadOptions() constructor to resolve path of external resources i.e. CSS/Images. For example the > tag’s src property provides the relative path. The final image path in the output HTML is basePath concatenated with the tag’s src in the HTML source.

String html = "<html><body>Australia<img src=\"australian_flag.jpg\" width=\"28\">abcd</body></html>";
java.io.InputStream is = new java.io.ByteArrayInputStream(html.getBytes());

com.aspose.pdf.HtmlLoadOptions htmlLoadOptions = new com.aspose.pdf.HtmlLoadOptions("E:/Data/Temp/");

Please feel free to contact us for any further assistance.

Best Regards,