pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1852386 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Date Mon, 28 Jan 2019 16:09:50 GMT
Author: tilman
Date: Mon Jan 28 16:09:50 2019
New Revision: 1852386

URL: http://svn.apache.org/viewvc?rev=1852386&view=rev
Log:
PDFBOX-4445: also merge /Language and /ViewerPreferences

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

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1852386&r1=1852385&r2=1852386&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Mon Jan 28 16:09:50 2019
@@ -72,6 +72,7 @@ import org.apache.pdfbox.pdmodel.interac
 import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
 import org.apache.pdfbox.pdmodel.interactive.form.PDField;
+import org.apache.pdfbox.pdmodel.interactive.viewerpreferences.PDViewerPreferences;
 
 /**
  * This class will take a list of pdf documents and merge them, saving the
@@ -840,6 +841,59 @@ public class PDFMergerUtility
             mergeRoleMap(srcStructTree, destStructTree);
             mergeIDTree(cloner, srcStructTree, destStructTree);
             mergeMarkInfo(destCatalog, srcCatalog);
+            mergeLanguage(destCatalog, srcCatalog);
+            mergeViewerPreferences(destCatalog, srcCatalog);
+        }
+    }
+
+    private void mergeViewerPreferences(PDDocumentCatalog destCatalog, PDDocumentCatalog
srcCatalog)
+    {
+        PDViewerPreferences srcViewerPreferences = srcCatalog.getViewerPreferences();
+        if (srcViewerPreferences == null)
+        {
+            return;
+        }
+        PDViewerPreferences destViewerPreferences = destCatalog.getViewerPreferences();
+        if (destViewerPreferences == null)
+        {
+            destViewerPreferences = new PDViewerPreferences(new COSDictionary());
+            destCatalog.setViewerPreferences(destViewerPreferences);
+        }
+        mergeInto(srcViewerPreferences.getCOSObject(), destViewerPreferences.getCOSObject(),
+                  Collections.<COSName>emptySet());
+
+        // check the booleans - set to true if one is set and true
+        if (srcViewerPreferences.hideToolbar() || destViewerPreferences.hideToolbar())
+        {
+            destViewerPreferences.setHideToolbar(true);
+        }
+        if (srcViewerPreferences.hideMenubar() || destViewerPreferences.hideMenubar())
+        {
+            destViewerPreferences.setHideMenubar(true);
+        }
+        if (srcViewerPreferences.hideWindowUI() || destViewerPreferences.hideWindowUI())
+        {
+            destViewerPreferences.setHideWindowUI(true);
+        }
+        if (srcViewerPreferences.fitWindow() || destViewerPreferences.fitWindow())
+        {
+            destViewerPreferences.setFitWindow(true);
+        }
+        if (srcViewerPreferences.centerWindow() || destViewerPreferences.centerWindow())
+        {
+            destViewerPreferences.setCenterWindow(true);
+        }
+        if (srcViewerPreferences.displayDocTitle() || destViewerPreferences.displayDocTitle())
+        {
+            destViewerPreferences.setDisplayDocTitle(true);
+        }
+    }
+
+    private void mergeLanguage(PDDocumentCatalog destCatalog, PDDocumentCatalog srcCatalog)
+    {
+        if (destCatalog.getLanguage() == null && srcCatalog.getLanguage() != null)
+        {
+            destCatalog.setLanguage(srcCatalog.getLanguage());
         }
     }
 



Mime
View raw message