Skip to content

Commit

Permalink
PDFBOX-5928: check whether the destination of a link annotation is an…
Browse files Browse the repository at this point in the history
… orphan

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922668 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Dec 24, 2024
1 parent 1ef50d6 commit 91f2db5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ public final class COSName extends COSBase implements Comparable<COSName>
public static final COSName LIGHTEN = getPDFName("Lighten");
public static final COSName LIMITS = getPDFName("Limits");
public static final COSName LINEARIZED = getPDFName("Linearized");
public static final COSName LINK = getPDFName("Link");
public static final COSName LJ = getPDFName("LJ");
public static final COSName LL = getPDFName("LL");
public static final COSName LLE = getPDFName("LLE");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement;
import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureNode;
import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureTreeRoot;
import org.apache.pdfbox.pdmodel.interactive.action.PDAction;
import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationPopup;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationText;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDNamedDestination;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageFitDestination;
Expand Down Expand Up @@ -915,10 +917,35 @@ else if (kdict.containsKey(COSName.NUMS))
{
COSDictionary obj = (COSDictionary) kdict.getDictionaryObject(COSName.OBJ);
COSBase type = obj.getDictionaryObject(COSName.TYPE);
if (COSName.ANNOT.equals(type))
COSBase subtype = obj.getDictionaryObject(COSName.SUBTYPE);
if (COSName.ANNOT.equals(type) || COSName.LINK.equals(subtype))
{
PDAnnotation annotation = PDAnnotation.createAnnotation(obj);
PDPage page = annotation.getPage();
if (annotation instanceof PDAnnotationLink)
{
PDAnnotationLink link = (PDAnnotationLink) annotation;
PDDestination destination = link.getDestination();
if (destination == null)
{
PDAction action = link.getAction();
if (action instanceof PDActionGoTo)
{
PDActionGoTo goToAction = (PDActionGoTo) action;
destination = goToAction.getDestination();
}
}
if (destination instanceof PDPageDestination)
{
PDPageDestination pageDestination = (PDPageDestination) destination;
PDPage destPage = pageDestination.getPage();
if (destPage != null)
{
assertNotEquals(-1, pageTree.indexOf(destPage),
"Annotation destination page is not in the page tree: " + destPage);
}
}
}
if (page != null)
{
if (pageTree.indexOf(page) == -1)
Expand All @@ -942,7 +969,7 @@ else if (kdict.containsKey(COSName.NUMS))
{
//TODO needs to be investigated. Specification mentions
// "such as an XObject or an annotation"
fail("Other type: " + type);
fail("Other type: " + type + ", obj: " + obj);
}
}
}
Expand Down

0 comments on commit 91f2db5

Please sign in to comment.