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

Free Support Forum - aspose.com

Convert HTML to PDF using URL in Java with Aspose.PDF for Java - Styles and images are not rendered correctly

We are planning to convert webpage url to PDF as per our requirement. For example
we have web page url : https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html
This url ends with an extension .html. So when an end user replaces .html with .pdf then we would like to show the PDF version of that webpage.

When we go through the ASPOSE API, we came to know that it will possible using below code snippet using java:

// Create and initialize URL
URL oracleURL = new URL("https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html");
// Get web page as input stream
InputStream is = oracleURL.openStream();
// Initialize HTML load options
HtmlLoadOptions htmloptions = new HtmlLoadOptions();
// Load stream into Document object
Document pdfDocument = new Document(is, htmloptions);
// Save output as PDF format

Also tried by adding base path as shown below:

String basePath = "basePath";
HtmlLoadOptions htmloptions = new HtmlLoadOptions(basePath);

But, when tried with our web page urls we observed that styles, images are missing in generated pdf and also content is overlapped when tried with base path settings.

We would like to connect with your technical team once to check about our requirement will be achievable with ASPOSE API or not ? else are we missing anything ?

Thank you.


In case your web pages are live and able to access, would you kindly share the URLs with us so that we can test the scenario in our environment and get back to you with our feedback.


Thank you so much for reply.

This is the URL: https://www.eaton.com/us/en-us/skuPage.BR120.html which we need to generate the PDF version. But with the above mentioned code by using this URL, we are facing issues with styling and images.

Please let us know what could be the issue.

Thank you.


We were able to notice the similar issue in our environment while using Aspose.PDF for Java 20.9. We have logged it as PDFJAVA-39778 in our issue management system for further investigation. We will look into its details and keep you informed about its rectification status. Please be patient and spare us some time.

We apologize for the inconvenience.