You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2024/12/24 08:58:49 UTC
svn commit: r1922666 - in /pdfbox/branches/3.0/pdfbox/src: main/java/org/apache/pdfbox/cos/COSName.java test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Author: tilman
Date: Tue Dec 24 08:58:48 2024
New Revision: 1922666
URL: http://svn.apache.org/viewvc?rev=1922666&view=rev
Log:
PDFBOX-5928: check whether the destination of a link annotation is an orphan
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1922666&r1=1922665&r2=1922666&view=diff
==============================================================================
--- pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java Tue Dec 24 08:58:48 2024
@@ -370,6 +370,7 @@ public final class COSName extends COSBa
public static final COSName LIGHTEN = new COSName("Lighten");
public static final COSName LIMITS = new COSName("Limits");
public static final COSName LINEARIZED = new COSName("Linearized");
+ public static final COSName LINK = getPDFName("Link");
public static final COSName LJ = new COSName("LJ");
public static final COSName LL = new COSName("LL");
public static final COSName LLE = new COSName("LLE");
Modified: pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java?rev=1922666&r1=1922665&r2=1922666&view=diff
==============================================================================
--- pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java (original)
+++ pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java Tue Dec 24 08:58:48 2024
@@ -46,12 +46,14 @@ import org.apache.pdfbox.pdmodel.common.
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;
@@ -916,10 +918,35 @@ class PDFMergerUtilityTest
{
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)
@@ -943,7 +970,7 @@ class PDFMergerUtilityTest
{
//TODO needs to be investigated. Specification mentions
// "such as an XObject or an annotation"
- fail("Other type: " + type);
+ fail("Other type: " + type + ", obj: " + obj);
}
}
}