PdfBox-Android icon indicating copy to clipboard operation
PdfBox-Android copied to clipboard

Does not render PDF with annotations 100%

Open ToysoftInc opened this issue 5 years ago • 12 comments

I have pdf with annotations and the rendered image is incomplete and missing alot of content.

ToysoftInc avatar Dec 03 '18 18:12 ToysoftInc

Please attach your PDF.

THausherr avatar Feb 22 '19 13:02 THausherr

Here is the sample pdf. The password is 123456 I'm just rendering the first page.

sample_protected.pdf

Here is what it rendered.

render

ToysoftInc avatar Feb 22 '19 16:02 ToysoftInc

Most be some Android specific problem. I tried with PDFBox for desktop from 1.8.16 down to 1.8.1 and it displays nicely.

THausherr avatar Feb 22 '19 18:02 THausherr

can you confirm if this is the problem with the current Android build?

ToysoftInc avatar Feb 22 '19 18:02 ToysoftInc

Don't know, I'm not developing for Android currently. I thought this was a problem with annotations and I was wondering whether it would fail with the desktop project.

THausherr avatar Feb 22 '19 18:02 THausherr

This is an definitely an Android specific problem. It looks like it's being caused by PageDrawer.getCurrentPoint(), which is basically unimplemented due to a difference in Android's Path class vs. Java's GeneralPath.

TomRoush avatar Feb 23 '19 05:02 TomRoush

That makes sense, the two lines appear to go in the direction (0,0). getCurrentPoint is only used by CurveToReplicateInitialPoint ("v"), which is used twice in the content stream of page 1. But that should be easy to fix, by storing the current point when moveTo, lineTo and curveTo are called.

THausherr avatar Feb 23 '19 09:02 THausherr

Implementing that properly fixed a couple of the rendered artifacts, but there are still bugs from #92 that I need to debug to get the rest of the letters to render.

TomRoush avatar Feb 24 '19 07:02 TomRoush

Cool. Please let me know when this is fixed. Need annotation in our project badly.

ToysoftInc avatar Feb 25 '19 16:02 ToysoftInc

From what I see (PageDrawer.java), the current Android code does not support rendering of annotations that don't have an appearance stream, only those that have. The 2.0 released version for desktop supports rendering of Link and Ink annotations. There is uncommitted code for 2.0 attached in https://issues.apache.org/jira/browse/PDFBOX-3353 for more annotation types. It is uncommitted because it became too bulky. Further development was done for the trunk only, which can display most annotation types.

THausherr avatar Feb 26 '19 11:02 THausherr

I downloaded https://github.com/barteksc/AndroidPdfViewer and I can view annotations.

Are both library using the same pdfbox build?

ToysoftInc avatar Feb 26 '19 17:02 ToysoftInc

AndroidPdfViewer uses PdfiumAndroid for rendering, not PDFBox, which is why you're able to see your annotations.

TomRoush avatar Mar 16 '19 18:03 TomRoush