Convert HTML to PDF using URL in Java with Aspose.PDF for Java (Url creating from angular)

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
pdfDocument.save("HTML-to-PDF.pdf");

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.

@kalpeshAspose1997,

First a very important question: what version of the API are you using? are you using the latest 23.3?

Second, can you verify the stream is correct by saving it to disk as an HTML file? Can you do this to one or two examples of sites that were wrong?

I want to validate that the stream is bringing all the styles. Because maybe that is where they are lost.

Let’s see this first and then continue with the rest of the requirements.

@carlos.molina, nope, I have tried with 22.11 and 23.3 version of the API but the output will same that attached
output file : output.pdf (82.7 KB)

@kalpeshAspose1997,

There seems to be an existing ticket related to this issue. I will link this post to that ticket. So there is a notice that more users need this fixed.

@kalpeshAspose1997
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): PDFJAVA-39778

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.