pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1853463 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java
Date Tue, 12 Feb 2019 18:07:51 GMT
Author: tilman
Date: Tue Feb 12 18:07:50 2019
New Revision: 1853463

URL: http://svn.apache.org/viewvc?rev=1853463&view=rev
Log:
PDFBOX-4459: make sure we have hit a pages node (previous code returned 0 on an isolated page)

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java?rev=1853463&r1=1853462&r2=1853463&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java
Tue Feb 12 18:07:50 2019
@@ -165,20 +165,29 @@ public abstract class PDPageDestination
             }
             else if (page instanceof COSDictionary)
             {
-                //TODO make this a static utility method of PDPageTree?
-                COSBase parent = page;
-                while (((COSDictionary) parent).getDictionaryObject(COSName.PARENT, COSName.P)
!= null)
-                {
-                    parent = ((COSDictionary) parent).getDictionaryObject(COSName.PARENT,
COSName.P);
-                }
-                // now parent is the pages node
-                PDPageTree pages = new PDPageTree((COSDictionary) parent);
-                return pages.indexOf(new PDPage((COSDictionary) page));
+                return indexOfPageTree((COSDictionary) page);
             }
         }
         return retval;
     }
 
+    // climb up the page tree up to the top to be able to call PageTree.indexOf for a page
dictionary
+    private int indexOfPageTree(COSDictionary pageDict)
+    {
+        COSDictionary parent = pageDict;
+        while (parent.getDictionaryObject(COSName.PARENT, COSName.P) instanceof COSDictionary)
+        {
+            parent = (COSDictionary) parent.getDictionaryObject(COSName.PARENT, COSName.P);
+        }
+        if (parent.containsKey(COSName.KIDS) && COSName.PAGES.equals(parent.getItem(COSName.TYPE)))
+        {
+            // now parent is the highest pages node
+            PDPageTree pages = new PDPageTree(parent);
+            return pages.indexOf(new PDPage(pageDict));
+        }
+        return -1;
+    }
+
     /**
      * Set the page number for a remote destination. For an internal destination, call 
      * {@link #setPage(PDPage) setPage(PDPage page)}.



Mime
View raw message