pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1713970 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Date Thu, 12 Nov 2015 07:40:20 GMT
Author: msahyoun
Date: Thu Nov 12 07:40:20 2015
New Revision: 1713970

URL: http://svn.apache.org/viewvc?rev=1713970&view=rev
Log:
PDFBOX-3094: determine unique field number between individual runs

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=1713970&r1=1713969&r2=1713970&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 Thu
Nov 12 07:40:20 2015
@@ -548,9 +548,26 @@ public class PDFMergerUtility
     private void mergeAcroForm(PDFCloneUtility cloner, PDAcroForm destAcroForm, PDAcroForm
srcAcroForm)
             throws IOException
     {
-        List<PDField> srcFields = srcAcroForm.getFields();
+
+    	List<PDField> srcFields = srcAcroForm.getFields();
+
         if (srcFields != null)
         {
+        	// if a form is merged multiple times using PDFBox the newly generated
+        	// fields starting with dummyFieldName may already exist. We need to determine the
last unique 
+        	// number used and increment that.
+        	final String prefix = "dummyFieldName";
+        	final int prefixLength = prefix.length();
+
+            for (PDField destField : destAcroForm.getFieldTree())
+            {
+            	String fieldName = destField.getPartialName();
+            	if (fieldName.startsWith(prefix))
+            	{
+            		nextFieldNum = Math.max(nextFieldNum, Integer.parseInt(fieldName.substring(prefixLength,
fieldName.length()))+1);
+            	}
+            }
+        	
             COSArray destFields = (COSArray) destAcroForm.getCOSObject().getItem(COSName.FIELDS);
             for (PDField srcField : srcAcroForm.getFieldTree())
             {
@@ -559,7 +576,7 @@ public class PDFMergerUtility
                 // to prevent merge conflicts.
                 if (destAcroForm.getField(srcField.getFullyQualifiedName()) != null)
                 {
-                    dstField.setString(COSName.T, "dummyFieldName" + nextFieldNum++);
+                    dstField.setString(COSName.T, prefix + nextFieldNum++);
                 }
                 destFields.add(dstField);
             }



Mime
View raw message