Hi
I have pdf file with a lot of links. They generally look like this in Foxit.
[cid:[email protected]]
In notepad the links look something like this:
/Subtype /Link
/A 140 0 R
/Type /Annot
/Rect [561.26 196.299 572.598 234.567]
>>
endobj
140 0 obj
<<
/D [5 0 R /Fit]
/Next 307 0 R
/Type /Action
/S /GoTo
>>
endobj
When attempting to split the pdf using the following code:
final PDDocument p1PD = PDDocument.load(p1.toFile());
final Splitter splitter = new Splitter();
final List<PDDocument> listPDFPages1 = splitter.split(p1PD);
I get the following exception:
java.io.IOException: Error: can't convert to Destination
COSArray{[COSName{Fit}]}
at
org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination.create(PDDestination.java:98)
at
org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink.getDestination(PDAnnotationLink.java:148)
It is thrown from PDDestination.create(COSBase base):98.
It happens because base is an COSArray with only one item [COSName{fit}]
[cid:[email protected]]
If I change the code in Splitter to catch the exception and ignore it:
[cid:[email protected]]
It will process all the annotations and annotation links and simply ignore the
error.
The splitted pages now contain links that look like this:
91 0 obj
<<
/D [null /Fit]
/Next 178 0 R
/Type /Action
/S /GoTo
>>
endobj
Now instead of /D [5 0 R /Fit] it is /D [null /Fit]
If I now try to process the annotations of the page
PDAnnotationLink.getDestination will not throw an Exception anymore because the
argument base will contain an COSArray the contains two items
[COSNull{},COSName{fit}]
I don't know how to interpret this. My solution for right now is to use my own
customized copy of the Splitter class that simply absorb the exception.
I feel like that for some reason PDFBox is ignoring the 5 0 R part of /D [5 0 R
/Fit] when building the annotations. I don't know enough about the PDF Spec to
tell what it does.
I am using PDFBox 2.0.27
BR
Thomas