Hi,
hopefully the below issue can be solved with your help.
First of all:
- I already had NP Problems converting HTML to PDF that manifested themselves in a similar way and could be traced back to missing fonts - this does not seem the case here.
- I have already tested various call options with HTML load Options etc. - nothing worked.
My current installation is 25.8, but I also got the same error with 25.12. Java Version 11.
Problem Description:
When using the HTML to PDF conversion in java, NP in the aspose-pdf library occurs when started from the application.
The identical HTML file is converted in a unit test without any problems. Also an extended unit test with call of the converter method directly in the jar file - as it also takes place from the app works. As far as I can see, the call in both cases does not differ in any settings or parameters. The unit test runs on the same machine as the application. Both share the same Linux environment.
I must check up if the HTML file causing the NP can be attached here.
The NP:
Caused by: java.lang.NullPointerException
at com.aspose.pdf.internal.l114v.l0p.lI(Unknown Source)
at com.aspose.pdf.internal.l114v.l1p.lI(Unknown Source)
at com.aspose.pdf.internal.l114v.ld$9.lI(Unknown Source)
Code snip:
String base = in.getParentFile().toURI().toString();
String html = Files.readString(in.toPath(), UTF_8);
String withBase = html.replaceFirst("(?is)<head\b[^>]*>", "<head><base href=\"" + base + "\">");
try (com.aspose.pdf.Document doc = new com.aspose.pdf.Document()) {
doc.setPageInfo(pageInfo); // set BEFORE adding pages
com.aspose.pdf.Page page = doc.getPages().add();
com.aspose.pdf.HtmlFragment frag = new com.aspose.pdf.HtmlFragment(withBase);
page.getParagraphs().add(frag);
doc.save(out.getAbsolutePath());
}