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/12 08:40:20 UTC
svn commit: r1713970 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
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);
}