You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2015/11/11 17:38:42 UTC

svn commit: r1713886 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java

Author: msahyoun
Date: Wed Nov 11 16:38:42 2015
New Revision: 1713886

URL: http://svn.apache.org/viewvc?rev=1713886&view=rev
Log:
PDFBOX-3094: add to existing fields; iterate over all source fields 

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1713886&r1=1713885&r2=1713886&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java Wed Nov 11 16:38:42 2015
@@ -22,6 +22,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -552,9 +553,8 @@ public class PDFMergerUtility
         List<PDField> srcFields = srcAcroForm.getFields();
         if (srcFields != null)
         {
-            List<COSDictionary> destFields = new ArrayList<COSDictionary>();
-            // fixme: we're only iterating over the root fields, names of kids aren't being checked
-            for (PDField srcField : srcFields)
+            COSArray destFields = (COSArray) destAcroForm.getCOSObject().getItem(COSName.FIELDS);
+            for (PDField srcField : srcAcroForm.getFieldTree())
             {
                 COSDictionary dstField = (COSDictionary) cloner.cloneForNewDocument(srcField.getCOSObject());
                 // if the form already has a field with this name then we need to rename this field
@@ -565,8 +565,7 @@ public class PDFMergerUtility
                 }
                 destFields.add(dstField);
             }
-            destAcroForm.getCOSObject().setItem(COSName.FIELDS,
-                                                COSArrayList.converterToCOSArray(destFields));
+            destAcroForm.getCOSObject().setItem(COSName.FIELDS,destFields);
         }
     }
 
@@ -687,5 +686,30 @@ public class PDFMergerUtility
     {
         return acroForm != null && acroForm.xfaIsDynamic();
     }
+    
+    private static String randomString(int length)
+    {
+        SecureRandom random = new SecureRandom();
+        char[] chars = new char[length];
+        for(int i=0;i<chars.length;i++)
+        {
+            int v = random.nextInt(10 + 26 + 26);
+            char c;
+            if (v < 10)
+            {
+                c = (char)('0' + v);
+            }
+            else if (v < 36)
+            {
+                c = (char)('a' - 10 + v);
+            }
+            else
+            {
+                c = (char)('A' - 36 + v);
+            }
+            chars[i] = c;
+        }
+        return new String(chars);
+    }
 
 }