Hey there!
So I’ve been looking into using Aspose.pdf java to implement an html to java implementation. Unfortunately, I’m running into timeout issues regarding how HTMLLoadOptions pulls/loads embedded css/js links. My assumption is that it doesn’t carry the basic java SSL authentication I provide it and because of lacking the creds it times out on the relative css/js paths within the html.
I tried setting the ExternalResourcesCredentials property as well but seems this was carried over from the .NET version of your library which uses NetworkCredential from C#/.NET that’s essentially optimized for credentials carried through the lifecycle of windows systems (I am on unix based system).
NetworkCredential link: NetworkCredential Class (System.Net) | Microsoft Learn
I also saw on the .NET docs you have a working example of ExternalResourcesCredentials available but not for the java version of the library:
Can you provide any insight on how to implement the ExternalResourcesCredentials for java using keystore/jks authentication?
Unfortunately I can’t share the document versions I have tested on because they’re private, but below is sample code I used:
// Setting aspose Temp License
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream iStreamLic = cl.getResourceAsStream("<license>");
License license = new License();
license.setLicense(iStreamLic);
// temp ssl configuration using java.net.*
//disableSslVerification();
setSSL();
// Converting resource to PDF
// https://blog.aspose.com/2020/01/30/convert-html-to-pdf-in-java/
String urlString = new String(resource.getByteArray(), StandardCharsets.UTF_8);
URL url = new URL(urlString);
String baseUrl = url.getProtocol() + "://" + url.getHost();
URLConnection conn = url.openConnection();
HtmlLoadOptions htmlOptions = new HtmlLoadOptions(baseUrl);
htmlOptions.ExternalResourcesCredentials = new NetworkCredential(
"<username>",
"<password>",
"<domain>"
); // this is the statement I'm having issue with
htmlOptions.getPageInfo().setLandscape(true);
htmlOptions.getPageInfo().setHeight(PageSize.getA4().getHeight());
htmlOptions.getPageInfo().setWidth(PageSize.getA4().getWidth());
Document doc = new Document(conn.getInputStream(), htmlOptions);
doc.save(os);
The output pdf excludes any styling generated from external css/js files in the html. Look forward to your response, thanks!