4646import org .apache .pdfbox .pdmodel .documentinterchange .logicalstructure .PDStructureElement ;
4747import org .apache .pdfbox .pdmodel .documentinterchange .logicalstructure .PDStructureNode ;
4848import org .apache .pdfbox .pdmodel .documentinterchange .logicalstructure .PDStructureTreeRoot ;
49+ import org .apache .pdfbox .pdmodel .interactive .action .PDAction ;
4950import org .apache .pdfbox .pdmodel .interactive .action .PDActionGoTo ;
5051import org .apache .pdfbox .pdmodel .interactive .annotation .PDAnnotation ;
5152import org .apache .pdfbox .pdmodel .interactive .annotation .PDAnnotationLink ;
5253import org .apache .pdfbox .pdmodel .interactive .annotation .PDAnnotationPopup ;
5354import org .apache .pdfbox .pdmodel .interactive .annotation .PDAnnotationText ;
5455import org .apache .pdfbox .pdmodel .interactive .annotation .PDAnnotationWidget ;
56+ import org .apache .pdfbox .pdmodel .interactive .documentnavigation .destination .PDDestination ;
5557import org .apache .pdfbox .pdmodel .interactive .documentnavigation .destination .PDNamedDestination ;
5658import org .apache .pdfbox .pdmodel .interactive .documentnavigation .destination .PDPageDestination ;
5759import org .apache .pdfbox .pdmodel .interactive .documentnavigation .destination .PDPageFitDestination ;
@@ -915,10 +917,35 @@ else if (kdict.containsKey(COSName.NUMS))
915917 {
916918 COSDictionary obj = (COSDictionary ) kdict .getDictionaryObject (COSName .OBJ );
917919 COSBase type = obj .getDictionaryObject (COSName .TYPE );
918- if (COSName .ANNOT .equals (type ))
920+ COSBase subtype = obj .getDictionaryObject (COSName .SUBTYPE );
921+ if (COSName .ANNOT .equals (type ) || COSName .LINK .equals (subtype ))
919922 {
920923 PDAnnotation annotation = PDAnnotation .createAnnotation (obj );
921924 PDPage page = annotation .getPage ();
925+ if (annotation instanceof PDAnnotationLink )
926+ {
927+ PDAnnotationLink link = (PDAnnotationLink ) annotation ;
928+ PDDestination destination = link .getDestination ();
929+ if (destination == null )
930+ {
931+ PDAction action = link .getAction ();
932+ if (action instanceof PDActionGoTo )
933+ {
934+ PDActionGoTo goToAction = (PDActionGoTo ) action ;
935+ destination = goToAction .getDestination ();
936+ }
937+ }
938+ if (destination instanceof PDPageDestination )
939+ {
940+ PDPageDestination pageDestination = (PDPageDestination ) destination ;
941+ PDPage destPage = pageDestination .getPage ();
942+ if (destPage != null )
943+ {
944+ assertNotEquals (-1 , pageTree .indexOf (destPage ),
945+ "Annotation destination page is not in the page tree: " + destPage );
946+ }
947+ }
948+ }
922949 if (page != null )
923950 {
924951 if (pageTree .indexOf (page ) == -1 )
@@ -942,7 +969,7 @@ else if (kdict.containsKey(COSName.NUMS))
942969 {
943970 //TODO needs to be investigated. Specification mentions
944971 // "such as an XObject or an annotation"
945- fail ("Other type: " + type );
972+ fail ("Other type: " + type + ", obj: " + obj );
946973 }
947974 }
948975 }
0 commit comments