You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ju...@apache.org on 2010/02/09 01:14:28 UTC
svn commit: r907852 -
/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java
Author: jukka
Date: Tue Feb 9 00:14:28 2010
New Revision: 907852
URL: http://svn.apache.org/viewvc?rev=907852&view=rev
Log:
PDFBOX-558: PDPageDestination getPageNumber only returns page number when underlying COSArray has a page number
Add a PDPageDestionation.findPageNumber() to complement the existing getPageNumber() method. Based on the patch contributed by Wulf Berschin.
Modified:
pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java
Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java?rev=907852&r1=907851&r2=907852&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java Tue Feb 9 00:14:28 2010
@@ -16,12 +16,16 @@
*/
package org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSNumber;
import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDPageNode;
/**
* This represents a destination to a page, see subclasses for specific parameters.
@@ -110,6 +114,39 @@
}
/**
+ * Returns the page number for this destination, regardless of whether
+ * this is a page number or a reference to a page.
+ *
+ * @since Apache PDFBox 1.0.0
+ * @see PDOutlineItem
+ * @return page number, or -1 if the destination type is unknown
+ */
+ public int findPageNumber() {
+ int retval = -1;
+ if( array.size() > 0 )
+ {
+ COSBase page = array.getObject( 0 );
+ if( page instanceof COSNumber )
+ {
+ retval = ((COSNumber)page).intValue();
+ }
+ else if (page instanceof COSDictionary)
+ {
+ COSBase parent = page;
+ while (((COSDictionary) parent).getDictionaryObject("Parent", "P") != null) {
+ parent = ((COSDictionary) parent).getDictionaryObject( "Parent", "P" );
+ }
+ // now parent is the pages node
+ PDPageNode pages = new PDPageNode((COSDictionary) parent);
+ List<PDPage> allPages = new ArrayList<PDPage>();
+ pages.getAllKids(allPages);
+ retval = allPages.indexOf(new PDPage((COSDictionary) page)) + 1;
+ }
+ }
+ return retval;
+ }
+
+ /**
* Set the page number for this destination.
*
* @param pageNumber The page for the destination.