danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!

Home Page:https://danfickle.github.io/pdf-templates/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting a nullptr exception, reproduction case included

ThomHurks opened this issue · comments

Hi!

First of all, it's been great using your library. Good work!

I noticed that with certain content (part of the content I include in the HTML is generated) I'm getting a crash when the PDF is generated. I managed to reduce the problem to a case that is pretty minimal I think;
https://github.com/ThomHurks/openhtmltopdfcrash

The nullpointer exception happens when OpenHtmlToPdf calls org.apache.pdfbox.cos.COSArray.add(COSArray.java:62)

If you need any help in figuring out the problem, please let me know!

Full stacktrace:

com.openhtmltopdf.general INFO:: Using fast-mode renderer. Prepare to fly.


java.lang.NullPointerException
	at org.apache.pdfbox.cos.COSArray.add(COSArray.java:62)
	at com.openhtmltopdf.pdfboxout.PdfBoxAccessibilityHelper.finishNumberTree(PdfBoxAccessibilityHelper.java:847)
	at com.openhtmltopdf.pdfboxout.PdfBoxFastOutputDevice.finish(PdfBoxFastOutputDevice.java:911)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.writePDFFast(PdfBoxRenderer.java:670)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.createPdfFast(PdfBoxRenderer.java:559)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.createPDF(PdfBoxRenderer.java:477)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.createPDF(PdfBoxRenderer.java:414)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.createPDF(PdfBoxRenderer.java:396)
	at com.openhtmltopdf.pdfboxout.PdfRendererBuilder.run(PdfRendererBuilder.java:42)
	at com.example.openhtmltopdfcrash.OpenHtmlToPdfCrash.reproduce(OpenHtmlToPdfCrash.java:34)

hi @ThomHurks , thank you for providing a minimal test case.

It seems to be the same issue as #527 and #401

@ThomHurks, @syjer

Thanks for the test case! After much debugging (at least six hours!), it turns out the core problem is that content (the last table row specifically) is being repeated where it shouldn't be in the page margins (not visibly) (and the accessibility code doesn't act well on this bug). This is similar to #458.

I was able to finally reproduce in a smaller sample and I have committed this as a (failing currently) test case. I will continue working on this to fix it.

Thanks again.

Thanks a lot for the help, @danfickle! That sounds like a die-hard debugging session. Great work you're doing here 👍

Hi @ThomHurks,

I have added PR #610 that fixes this problem. However, I just need to create some more tests before merging and then I can do a release finally.

@danfickle Thanks a lot! Amazing job 👌