diff --git a/src/main/java/org/verapdf/pd/PDAnnotation.java b/src/main/java/org/verapdf/pd/PDAnnotation.java index c1499e69..82a19a2f 100644 --- a/src/main/java/org/verapdf/pd/PDAnnotation.java +++ b/src/main/java/org/verapdf/pd/PDAnnotation.java @@ -27,6 +27,7 @@ import org.verapdf.exceptions.LoopedException; import org.verapdf.pd.actions.PDAction; import org.verapdf.pd.actions.PDAnnotationAdditionalActions; +import org.verapdf.tools.StaticResources; import org.verapdf.tools.TypeConverter; import java.util.HashSet; @@ -290,4 +291,36 @@ public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) { } return null; } + + public static COSObject getPageFromDestination(COSObject destination, ASAtom key) { + if (destination.getType() == COSObjType.COS_STRING) { + PDNamesDictionary namesDictionary = StaticResources.getDocument().getCatalog().getNamesDictionary(); + if (namesDictionary == null) { + return null; + } + PDNameTreeNode dests = namesDictionary.getDests(); + if (dests != null) { + destination = dests.getObject(destination.getString()); + if (destination == null) { + return null; + } + } + } else if (destination.getType() == COSObjType.COS_NAME) { + COSObject dests = StaticResources.getDocument().getCatalog().getDests(); + if (dests != null) { + destination = dests.getKey(destination.getDirectBase().getName()); + if (destination == null) { + return null; + } + } + } + if (destination.getType() == COSObjType.COS_DICT) { + destination = destination.getKey(key); + } + COSObject obj = null; + if (destination.getType() == COSObjType.COS_ARRAY && destination.size() > 0) { + obj = destination.at(0); + } + return obj; + } }