pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1818331 - in /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox: cos/COSName.java pdmodel/PDPage.java
Date Fri, 15 Dec 2017 20:41:41 GMT
Author: tilman
Date: Fri Dec 15 20:41:41 2017
New Revision: 1818331

URL: http://svn.apache.org/viewvc?rev=1818331&view=rev
Log:
PDFBOX-4040: add viewport getter / setter

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1818331&r1=1818330&r2=1818331&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java Fri Dec 15
20:41:41 2017
@@ -550,6 +550,7 @@ public final class COSName extends COSBa
     public static final COSName VIEW_CLIP = new COSName("ViewClip");
     public static final COSName VIEWER_PREFERENCES = new COSName("ViewerPreferences");
     public static final COSName VOLUME = new COSName("Volume");
+    public static final COSName VP = new COSName("VP");
     // W
     public static final COSName W = new COSName("W");
     public static final COSName W2 = new COSName("W2");

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java?rev=1818331&r1=1818330&r2=1818331&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java Fri Dec
15 20:41:41 2017
@@ -41,6 +41,7 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.pdmodel.interactive.action.PDPageAdditionalActions;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
+import org.apache.pdfbox.pdmodel.interactive.measurement.PDViewportDictionary;
 import org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead;
 import org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDTransition;
 import org.apache.pdfbox.util.Matrix;
@@ -708,4 +709,53 @@ public class PDPage implements COSObject
     {
         return resourceCache;
     }
+
+    /**
+     * Get the viewports.
+     *
+     * @return a list of viewports or null if there is no /VP entry.
+     */
+    public List<PDViewportDictionary> getViewports()
+    {
+        COSBase base = page.getDictionaryObject(COSName.VP);
+        if (!(base instanceof COSArray))
+        {
+            return null;
+        }
+        COSArray array = (COSArray) base;
+        List<PDViewportDictionary> viewports = new ArrayList<PDViewportDictionary>();
+        for (int i = 0; i < array.size(); ++i)
+        {
+            COSBase base2 = array.getObject(i);
+            if (base2 instanceof COSDictionary)
+            {
+                viewports.add(new PDViewportDictionary((COSDictionary) base2));
+            }
+            else
+            {
+                LOG.warn("Array element " + base2 + " is skipped, must be a (viewport) dictionary");
+            }
+        }
+        return viewports;
+    }
+
+    /**
+     * Set the viewports.
+     *
+     * @param viewports A list of viewports, or null if the entry is to be deleted.
+     */
+    public void setViewports(List<PDViewportDictionary> viewports)
+    {
+        if (viewports == null)
+        {
+            page.removeItem(COSName.VP);
+            return;
+        }
+        COSArray array = new COSArray();
+        for (PDViewportDictionary viewport : viewports)
+        {
+            array.add(viewport);
+        }
+        page.setItem(COSName.VP, array);
+    }
 }



Mime
View raw message