pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1794146 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
Date Sat, 06 May 2017 14:13:59 GMT
Author: tilman
Date: Sat May  6 14:13:59 2017
New Revision: 1794146

URL: http://svn.apache.org/viewvc?rev=1794146&view=rev
Log:
PDFBOX-3781: insert xobjects instead of overwrite AcroForm /DR entry when it exists, as suggested
by Marco Monacelli

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1794146&r1=1794145&r2=1794146&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sat
May  6 14:13:59 2017
@@ -515,16 +515,32 @@ public class PDDocument implements Close
         signatureField.getWidgets().get(0).setAppearance(ap);
     }
 
-    private void assignAcroFormDefaultResource(PDAcroForm acroForm, COSDictionary dict)
+    private void assignAcroFormDefaultResource(PDAcroForm acroForm, COSDictionary newDict)
     {
-        // read and set AcroForm default resource dictionary /DR if available
-        COSBase base = dict.getDictionaryObject(COSName.DR);
-        if (base instanceof COSDictionary)
+        // read and set/update AcroForm default resource dictionary /DR if available
+        COSBase newBase = newDict.getDictionaryObject(COSName.DR);
+        if (newBase instanceof COSDictionary)
         {
-            COSDictionary dr = (COSDictionary) base;
-            dr.setDirect(true);
-            dr.setNeedToBeUpdated(true);
-            acroForm.getCOSObject().setItem(COSName.DR, dr);
+            COSDictionary newDR = (COSDictionary) newBase;
+            PDResources defaultResources = acroForm.getDefaultResources();
+            if (defaultResources == null)
+            {
+                acroForm.getCOSObject().setItem(COSName.DR, newDR);
+                newDR.setDirect(true);
+                newDR.setNeedToBeUpdated(true);            
+            }
+            else
+            {
+                COSDictionary oldDR = defaultResources.getCOSObject();
+                COSBase newXObjectBase = newDR.getItem(COSName.XOBJECT);
+                COSBase oldXObjectBase = oldDR.getItem(COSName.XOBJECT);
+                if (newXObjectBase instanceof COSDictionary &&
+                    oldXObjectBase instanceof COSDictionary)
+                {
+                    ((COSDictionary) oldXObjectBase).addAll((COSDictionary) newXObjectBase);
+                    oldDR.setNeedToBeUpdated(true);
+                }
+            }
         }
     }
 



Mime
View raw message