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

Free Support Forum - aspose.com

Problem converting html and css to pdf


The goal: To convert a html file with an image and css to a pdf file using Java.
The problem:
When the html file that I convert has no css it works fine. But when I add css, the resultant pdf is a bit messed up. The page size is different and the result is not similar to the the html page.

I've used inline css as I thought this might solve the problem originally.

Here is a sketch of the Java code I use to perform the conversion:

private void generatePDF(String html, String name){

String htmlPath = "my/path";
String pdfPath = "my/other/path";

HtmlLoadOptions htmlOptions = new HtmlLoadOptions(htmlpath);
htmlOptions.getPageInfo().setHeight(841.89);//A4 size

com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(htmlPath+File.separator+name, htmlOptions);

pdf.save(pdfPath + File.separator + name + ".pdf");


And I have attached the html file which I use to generate the pdf.

Looking forward hearing from you.

Hi Jon,

Thanks for your inquiry. I have tested HTML to PDF conversion scenario with shared HTML using Aspose.Pdf for Java 10.4.0 and managed to observe the reported issue. For further investigation, I have logged an issue in our issue tracking system as PDFNEWJAVA-34964 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

Please feel free to contact us for any further assistance.

<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:
mso-bidi-language:AR-SA”>Best Regards

Thank you for you response.

I hope to have the functionality in production in about 2 months, so obviously I’m looking forward to the issue being solved.

Best regards,

Hi Jon,

We do understand the criticallity of this and this problem is as equal and important for us, as any other issue and the product team will surely plan investigation/resolution of this problem, as per their development schedule. As soon as we have some definite updates regarding its resolution, we will let you know.

The issues you have found earlier (filed as PDFNEWJAVA-34964) have been fixed in Aspose.Pdf for Java 11.3.0.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.