Open CedricMtta opened 1 year ago
We kept digging a bit and it turned out that, with the Arial font and the html document named "cannot-render-in-arial.html", some GenericContentItem were created by the method "ensureAncestorTree". However, this method didn't set correctly the relationship between the latest created structural element and the existing ancestor. The fix can be found here => https://github.com/CedricMtta/openhtmltopdf/commit/4f62a27df439393c8224ac45aa25efbabae09e85#diff-bc184dd44f14edb67050aaf0c0fc0ddd3cbebeb261b77ee1450e2f23b39d5cedR954
(Thanks to @nithril for the help in finding this:))
I assume that working PDF rendering never triggers this function, otherwise the NPE would have occured.
It's still not clear to us why using Arial generate some null AccessilityObject that are then fixed by ensureAncestorTree.
@danfickle we'd be happy to have your opinion on this :)
Hello,
First of all, thanks for the work performed on this lib, it's really appreciated.
I work on a project using openhtmltopdf to generate PDF A_1_A compliant from quite big HTML files. We ran into the following stacktrace in some cases: `java.lang.NullPointerException: Cannot invoke "org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject()" because "object" is null
` It happens only when:
If I disable the A_1_A mode, it will work with Arial. If I use Karla instead of Arial, it will work with the A_1_A mode.
I tried to debug a bit to understand what leads to this NPE but without reaching an understanding so far.
I forked your repo from the 1.0.10 release and created a branch to reproduce the issue. You can find it here: https://github.com/CedricMtta/openhtmltopdf/blob/cedricmtta-error-with-big-html-and-some-fonts-reproduction/openhtmltopdf-pdfa-testing/src/test/java/com/openhtmltopdf/pdfa/testing/PdfATester.java
You can run PdfATester#canRenderInArial to see a quite big html document being rendered in Arial and A_1_A compliance successfully. You can run PdfATester#cannotRenderInArial to see the failure described above.
I don't understand how it could work in Karla but not Arial. The main difference I see between those two fonts is that Arial supports nearly any language, while Karla supports only western language.
I wonder whether I'm doing something wrong in the config or if the source HTML is broken, or if it's an issue in openhtmltopdf.
I'd appreciate any help, thanks a lot in advance :)
EDIT: It works with the Open Sans regular font, that can be found here https://www.fontsquirrel.com/fonts/open-sans This work is compatible with non-western characters, like Arial. I still cannot understand why the rendering with Arial throws an NPE :(