Skip to content

Commit dedc5b0

Browse files
Some bugs about acroforms were fixed.
1 parent d96ece7 commit dedc5b0

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

forms/src/main/java/com/itextpdf/forms/PdfPageFormCopier.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package com.itextpdf.forms;
22

33
import com.itextpdf.io.LogMessageConstant;
4-
import com.itextpdf.kernel.pdf.IPdfPageExtraCopier;
5-
import com.itextpdf.kernel.pdf.PdfDictionary;
6-
import com.itextpdf.kernel.pdf.PdfDocument;
7-
import com.itextpdf.kernel.pdf.PdfName;
8-
import com.itextpdf.kernel.pdf.PdfPage;
9-
import com.itextpdf.kernel.pdf.PdfString;
4+
import com.itextpdf.kernel.pdf.*;
105
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
116
import com.itextpdf.kernel.pdf.annot.PdfWidgetAnnotation;
127
import com.itextpdf.forms.fields.PdfFormField;
@@ -95,19 +90,26 @@ public void copy(PdfPage fromPage, PdfPage toPage) {
9590
}
9691

9792
private PdfFormField mergeFieldsWithTheSameName(PdfFormField existingField, PdfFormField newField) {
98-
PdfFormField mergedField = PdfFormField.createEmptyField(documentTo);
93+
String fieldName = newField.getFieldName().toUnicodeString();
94+
existingField.remove(PdfName.T);
95+
PdfFormField mergedField = formTo.getField(fieldName);
96+
PdfArray kids = mergedField.getKids();
97+
if (kids != null && !kids.isEmpty()) {
98+
mergedField.addKid(existingField);
99+
return mergedField;
100+
}
101+
newField.remove(PdfName.T);
102+
mergedField = PdfFormField.createEmptyField(documentTo);
99103
formTo.getFields().remove(newField.getPdfObject());
104+
//formTo.getFormFields().remove(fieldName);
100105
mergedField.
101106
put(PdfName.FT, existingField.getFormType()).
102-
put(PdfName.T, existingField.getFieldName()).
107+
put(PdfName.T, new PdfString(fieldName)).
103108
put(PdfName.Parent, existingField.getParent()).
104109
put(PdfName.Kids, existingField.getKids());
105110

106-
existingField.remove(PdfName.T);
107-
newField.remove(PdfName.T);
108111
mergedField.addKid(existingField).addKid(newField);
109112

110113
return mergedField;
111114
}
112-
113115
}

0 commit comments

Comments
 (0)