pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1806710 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java
Date Wed, 30 Aug 2017 16:25:49 GMT
Author: tilman
Date: Wed Aug 30 16:25:49 2017
New Revision: 1806710

URL: http://svn.apache.org/viewvc?rev=1806710&view=rev
Log:
PDFBOX-3914: no longer ignore OCProperties on import, as suggested by Ivan Khaldeev

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java?rev=1806710&r1=1806709&r2=1806710&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java
Wed Aug 30 16:25:49 2017
@@ -147,6 +147,8 @@ public class LayerUtility
      */
     public PDFormXObject importPageAsForm(PDDocument sourceDoc, PDPage page) throws IOException
     {
+        importOcProperties(sourceDoc);
+
         PDStream newStream = new PDStream(targetDoc, page.getContents(), COSName.FLATE_DECODE);
         PDFormXObject form = new PDFormXObject(newStream);
 
@@ -270,4 +272,34 @@ public class LayerUtility
                     cloner.cloneForNewDocument(entry.getValue()));
         }
     }
+
+    /**
+     * Imports OCProperties from source document to target document so hidden layers can
still be
+     * hidden after import.
+     *
+     * @param sourceDoc The source PDF document that contains the /OCProperties to be copied.
+     * @throws IOException If an I/O error occurs.
+     */
+    private void importOcProperties(PDDocument srcDoc) throws IOException
+    {
+        PDDocumentCatalog srcCatalog = srcDoc.getDocumentCatalog();
+        PDOptionalContentProperties srcOCProperties = srcCatalog.getOCProperties();
+        if (srcOCProperties == null)
+        {
+            return;
+        }
+
+        PDDocumentCatalog dstCatalog = targetDoc.getDocumentCatalog();
+        PDOptionalContentProperties dstOCProperties = dstCatalog.getOCProperties();
+
+        if (dstOCProperties == null)
+        {
+            dstCatalog.setOCProperties(new PDOptionalContentProperties(
+                    (COSDictionary) cloner.cloneForNewDocument(srcOCProperties)));
+        }
+        else
+        {
+            cloner.cloneMerge(srcOCProperties, dstOCProperties);
+        }
+    }
 }



Mime
View raw message