Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.24
-
None
Description
I have stumbled across a strange issue with a certain PDF where PDPage.getAnnotations() causes subsequent calls to PDDocument.getPages() to fail.
I am not at liberty to share the PDF publicly, but am happy to DM the PDF privately if it helps.
The code to reproduce is pretty straightforward:
import java.io.File; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; public class AnnotationsTest { public static void main(String[] args) throws Exception { try( PDDocument doc = PDDocument.load(new File(args[0]));){ for (PDPage page : doc.getPages()) { //this line will cause the doc to not be re-iterable in the next block, commenting it out will allow it to pass. page.getAnnotations(); } System.out.println("We get here, no problem - not sure why we can't re-iterate again..."); //doc.getPages() fails. for (PDPage page : doc.getPages()) { //do something } } }
The Exception:
Exception in thread "main" java.lang.IllegalStateException: Expected 'Page' but found COSName{Annot}Exception in thread "main" java.lang.IllegalStateException: Expected 'Page' but found COSName{Annot} at org.apache.pdfbox.pdmodel.PDPageTree.sanitizeType(PDPageTree.java:266) at org.apache.pdfbox.pdmodel.PDPageTree.access$400(PDPageTree.java:43) at org.apache.pdfbox.pdmodel.PDPageTree$PageIterator.next(PDPageTree.java:224) at org.apache.pdfbox.pdmodel.PDPageTree$PageIterator.next(PDPageTree.java:172) at AnnotationsTest.main(AnnotationsTest.java:28)