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 2015/05/11 08:48:45 UTC
svn commit: r1678680 - in
/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel:
PDDocumentCatalog.java PDDocumentNameDestinationDictionary.java
interactive/documentnavigation/outline/PDOutlineItem.java
Author: tilman
Date: Mon May 11 06:48:44 2015
New Revision: 1678680
URL: http://svn.apache.org/r1678680
Log:
PDFBOX-2793: add support of /Dests directory in /Catalog for name lookup in outline item
Added:
pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDestinationDictionary.java (with props)
Modified:
pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java
pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java?rev=1678680&r1=1678679&r2=1678680&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java Mon May 11 06:48:44 2015
@@ -409,6 +409,20 @@ public class PDDocumentCatalog implement
}
/**
+ * @return The named destinations dictionary for this document or null if none exists.
+ */
+ public PDDocumentNameDestinationDictionary getDests()
+ {
+ PDDocumentNameDestinationDictionary nameDic = null;
+ COSDictionary dests = (COSDictionary) root.getDictionaryObject(COSName.DESTS);
+ if (dests != null)
+ {
+ nameDic = new PDDocumentNameDestinationDictionary(dests);
+ }
+ return nameDic;
+ }
+
+ /**
* Set the names dictionary for the document.
*
* @param names The names dictionary that is associated with this document.
Added: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDestinationDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDestinationDictionary.java?rev=1678680&view=auto
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDestinationDictionary.java (added)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDestinationDictionary.java Mon May 11 06:48:44 2015
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel;
+
+import java.io.IOException;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
+import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
+
+/**
+ * This encapsulates the "dictionary of names and corresponding destinations" for the /Dest entry in
+ * the document catalog.
+ *
+ * @author Tilman Hausherr
+ */
+public class PDDocumentNameDestinationDictionary implements COSObjectable
+{
+ private final COSDictionary nameDictionary;
+
+ /**
+ * Constructor.
+ *
+ * @param dict The dictionary of names and corresponding destinations.
+ */
+ public PDDocumentNameDestinationDictionary(COSDictionary dict)
+ {
+ this.nameDictionary = dict;
+ }
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos dictionary for this object.
+ */
+ public COSDictionary getCOSObject()
+ {
+ return nameDictionary;
+ }
+
+ /**
+ * Returns the destination corresponding to the parameter.
+ *
+ * @param name The destination name.
+ * @return The destination for that name.
+ *
+ * @throws IOException if something goes wrong when creating the destination object.
+ */
+ public PDDestination getDestination(String name) throws IOException
+ {
+ COSBase item = nameDictionary.getDictionaryObject(name);
+ return PDDestination.create(item);
+ }
+
+
+}
Propchange: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDestinationDictionary.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java?rev=1678680&r1=1678679&r2=1678680&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java Mon May 11 06:48:44 2015
@@ -27,6 +27,7 @@ import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.exceptions.OutlineNotLocalException;
import org.apache.pdfbox.pdmodel.PDDestinationNameTreeNode;
import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDDocumentNameDestinationDictionary;
import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement;
@@ -253,6 +254,16 @@ public class PDOutlineItem extends PDOut
pageDest = (PDPageDestination)destsTree.getValue( namedDest.getNamedDestination() );
}
}
+ else
+ {
+ // Look up /Dests dictionary from catalog
+ PDDocumentNameDestinationDictionary nameDestDict = doc.getDocumentCatalog().getDests();
+ if (nameDestDict != null)
+ {
+ String name = namedDest.getNamedDestination();
+ pageDest = (PDPageDestination) nameDestDict.getDestination(name);
+ }
+ }
}
else if( rawDest instanceof PDPageDestination)
{