Repository: danfickle/openhtmltopdf

Issue #458: PDFTextStripper - parsing incorrectness
Created: 2020-03-12T18:20:00Z
Hello,
I am using PDFTextStripper, from the PDFbox library, to parse the text out of the pdf generated from html using openhtmltopdf.
Code for parsing:
final PDDocument document = PDDocument.load(pdfBytes);
final PDFTextStripper pdfTextStripper = new PDFTextStripper();
return pdfTextStripper.getText(document);
However, I am seeing a few problems:

Invisible, redundant text
sometimes the PDF will have invisible text in front of the actual text.
e.g.

HTML:
line1
line2
line3
PDF:
line1
line2 (<--- invisible)
line2
line3
This happens even when you just open the pdf and select / copy the text.

commas are places in the wrong position, when parsed
commas show up correctly, but when parsed, they show in incorrect position
e.g.
HTML:
hello, my name, is

PDF:
,,hello my name is
NOTE this does not happen when you open the pdf and select / copy the text.

Interestingly, the comma problem goes away when I parse like this
final PDDocument document = PDDocument.load(pdfBytes);
final PDFTextStripper pdfTextStripper = new PDFTextStripper();
pdfTextStripper.setSortByPosition(true);
return pdfTextStripper.getText(document);

However, all superscripts / subscripts then gets messed up on the output
e.g. receptiońs becomes receptións
Do you know why these happens?
Thank you!

Duplicate issue #594: Getting a nullptr exception, reproduction case included
Created: 2020-11-08T20:43:15Z
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)

Closing comment (2020-11-13T16:12:02Z): @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.