Skip to content

Commit a274601

Browse files
iText-CIEvgenyB1001
authored andcommitted
Merge branch 'release_branch_DEVSIX-5942' into master-rc
2 parents 87fffa6 + 6d5b066 commit a274601

File tree

559 files changed

+3839
-859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

559 files changed

+3839
-859
lines changed

barcodes/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.itextpdf</groupId>
66
<artifactId>root</artifactId>
7-
<version>7.1.16</version>
7+
<version>7.1.17</version>
88
</parent>
99
<artifactId>barcodes</artifactId>
1010
<name>iText 7 - barcodes</name>

font-asian/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.itextpdf</groupId>
66
<artifactId>root</artifactId>
7-
<version>7.1.16</version>
7+
<version>7.1.17</version>
88
</parent>
99
<artifactId>font-asian</artifactId>
1010
<name>iText 7 - Asian fonts</name>

forms/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.itextpdf</groupId>
66
<artifactId>root</artifactId>
7-
<version>7.1.16</version>
7+
<version>7.1.17</version>
88
</parent>
99
<artifactId>forms</artifactId>
1010
<name>iText 7 - forms</name>

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,14 @@ private void copyParentFormField(PdfPage toPage, Map<String, PdfFormField> field
167167
PdfAnnotation annot, PdfFormField parentField) {
168168
PdfString parentName = parentField.getFieldName();
169169
if (!fieldsTo.containsKey(parentName.toUnicodeString())) {
170+
// no such field, hence we should simply add it
170171
PdfFormField field = createParentFieldCopy(annot.getPdfObject(), documentTo);
171172
PdfArray kids = field.getKids();
172173
field.getPdfObject().remove(PdfName.Kids);
173174
formTo.addField(field, toPage);
174175
field.getPdfObject().put(PdfName.Kids, kids);
175176
} else {
177+
// it is either a field (field name will not be null) or a widget (field name is not null)
176178
PdfFormField field = makeFormField(annot.getPdfObject());
177179
if (field == null) {
178180
return;
@@ -190,18 +192,36 @@ private void copyParentFormField(PdfPage toPage, Map<String, PdfFormField> field
190192
fieldsTo);
191193
}
192194
} else {
193-
if (!parentField.getKids().contains(field.getPdfObject())) {
195+
if (!parentField.getKids().contains(field.getPdfObject())
196+
&& formTo.getFields().contains(parentField.getPdfObject())) {
197+
// its parent is already a field of the resultant document,
198+
// hence we only need to update its children
194199
HashSet<String> existingFields = new HashSet<>();
195200
getAllFieldNames(formTo.getFields(), existingFields);
196201
addChildToExistingParent(annot.getPdfObject(), existingFields);
202+
} else {
203+
// its parent is not a field of the resultant document, but the latter contains
204+
// a field of the same name, therefore we should merge them (note that merging in this context
205+
// differs from merging a widget and an annotation into a single entity)
206+
PdfFormField mergedField = mergeFieldsWithTheSameName(field);
207+
// we need to add the field not to its representation (#getFormFields()), but to
208+
// /Fields entry of the acro form
209+
formTo.addField(mergedField, toPage);
197210
}
198211
}
199212
}
200213
}
201214

202215
private PdfFormField mergeFieldsWithTheSameName(PdfFormField newField) {
203-
String fullFieldName = newField.getFieldName().toUnicodeString();
204216
PdfString fieldName = newField.getPdfObject().getAsString(PdfName.T);
217+
if (null == fieldName) {
218+
fieldName = newField.getParent().getAsString(PdfName.T);
219+
}
220+
221+
String fullFieldName = fieldName.toUnicodeString();
222+
if (null != newField.getFieldName()) {
223+
fullFieldName = newField.getFieldName().toUnicodeString();
224+
}
205225

206226
logger.warn(MessageFormatUtil.format(LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, fullFieldName));
207227

forms/src/test/java/com/itextpdf/forms/FormFieldFlatteningTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private static void fillTextFieldsThenFlattenThenCompare(String testName) throws
254254
}
255255

256256
@Test
257-
@LogMessages(messages = {@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 3)})
257+
@LogMessages(messages = {@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 5)})
258258
//Logging is expected since there are duplicate field names
259259
//isReadOnly should be true after DEVSIX-2156
260260
public void flattenReadOnly() throws IOException {

forms/src/test/java/com/itextpdf/forms/PdfFormCopyTest.java

Lines changed: 112 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This file is part of the iText (R) project.
5353
import com.itextpdf.test.annotations.LogMessage;
5454
import com.itextpdf.test.annotations.LogMessages;
5555
import com.itextpdf.test.annotations.type.IntegrationTest;
56+
5657
import org.junit.Assert;
5758
import org.junit.BeforeClass;
5859
import org.junit.Test;
@@ -63,8 +64,8 @@ This file is part of the iText (R) project.
6364
@Category(IntegrationTest.class)
6465
public class PdfFormCopyTest extends ExtendedITextTest {
6566

66-
public static final String sourceFolder = "./src/test/resources/com/itextpdf/forms/PdfFormFieldsCopyTest/";
67-
public static final String destinationFolder = "./target/test/com/itextpdf/forms/PdfFormFieldsCopyTest/";
67+
public static final String sourceFolder = "./src/test/resources/com/itextpdf/forms/PdfFormCopyTest/";
68+
public static final String destinationFolder = "./target/test/com/itextpdf/forms/PdfFormCopyTest/";
6869

6970
@BeforeClass
7071
public static void beforeClass() {
@@ -73,7 +74,7 @@ public static void beforeClass() {
7374

7475
@Test
7576
@LogMessages(messages = {
76-
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 13)
77+
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 32)
7778
})
7879
public void copyFieldsTest01() throws IOException, InterruptedException {
7980
String srcFilename1 = sourceFolder + "appearances1.pdf";
@@ -328,7 +329,7 @@ public void copyFieldsTest06() throws IOException, InterruptedException {
328329

329330
@Test
330331
@LogMessages(messages = {
331-
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 13)
332+
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 32)
332333
})
333334
public void copyFieldsTest07() throws IOException, InterruptedException {
334335
String srcFilename = sourceFolder + "datasheet.pdf";
@@ -350,7 +351,7 @@ public void copyFieldsTest07() throws IOException, InterruptedException {
350351

351352
@Test
352353
@LogMessages(messages = {
353-
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 13)
354+
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 32)
354355
})
355356
public void copyFieldsTest08() throws IOException, InterruptedException {
356357
String srcFilename1 = sourceFolder + "appearances1.pdf";
@@ -378,7 +379,7 @@ public void copyFieldsTest08() throws IOException, InterruptedException {
378379

379380
@Test
380381
@LogMessages(messages = {
381-
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 26)
382+
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 64)
382383
})
383384
public void copyFieldsTest09() throws IOException, InterruptedException {
384385
String srcFilename = sourceFolder + "datasheet.pdf";
@@ -516,9 +517,9 @@ public void unnamedFieldsHierarchyTest() throws IOException, InterruptedExceptio
516517
})
517518
public void copyAndEditTextFields() throws IOException, InterruptedException {
518519
//TODO: update after DEVSIX-2354
519-
String srcFileName = sourceFolder + "/checkPdfFormCopy_Source.pdf";
520+
String srcFileName = sourceFolder + "checkPdfFormCopy_Source.pdf";
520521
String destFilename = destinationFolder + "copyAndEditTextFields.pdf";
521-
String cmpFileName = sourceFolder + "/cmp_copyAndEditTextFields.pdf";
522+
String cmpFileName = sourceFolder + "cmp_copyAndEditTextFields.pdf";
522523

523524
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFileName));
524525
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
@@ -547,9 +548,9 @@ public void copyAndEditTextFields() throws IOException, InterruptedException {
547548
})
548549
public void copyAndEditCheckboxes() throws IOException, InterruptedException {
549550
//TODO: update after DEVSIX-2354
550-
String srcFileName = sourceFolder + "/checkPdfFormCopy_Source.pdf";
551+
String srcFileName = sourceFolder + "checkPdfFormCopy_Source.pdf";
551552
String destFilename = destinationFolder + "copyAndEditCheckboxes.pdf";
552-
String cmpFileName = sourceFolder + "/cmp_copyAndEditCheckboxes.pdf";
553+
String cmpFileName = sourceFolder + "cmp_copyAndEditCheckboxes.pdf";
553554

554555
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFileName));
555556
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
@@ -576,9 +577,9 @@ public void copyAndEditCheckboxes() throws IOException, InterruptedException {
576577
})
577578
public void copyAndEditRadioButtons() throws IOException, InterruptedException {
578579
//TODO: update after DEVSIX-2354
579-
String srcFileName = sourceFolder + "/checkPdfFormCopy_Source.pdf";
580+
String srcFileName = sourceFolder + "checkPdfFormCopy_Source.pdf";
580581
String destFilename = destinationFolder + "copyAndEditRadioButtons.pdf";
581-
String cmpFileName = sourceFolder + "/cmp_copyAndEditRadioButtons.pdf";
582+
String cmpFileName = sourceFolder + "cmp_copyAndEditRadioButtons.pdf";
582583

583584
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFileName));
584585
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
@@ -596,4 +597,103 @@ public void copyAndEditRadioButtons() throws IOException, InterruptedException {
596597

597598
Assert.assertNull(new CompareTool().compareByContent(destFilename, cmpFileName, destinationFolder, "diff_"));
598599
}
600+
601+
@Test
602+
@LogMessages(messages = {
603+
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD)
604+
})
605+
public void mergeMergedFieldAndMergedFieldTest() throws IOException, InterruptedException {
606+
String srcFileName1 = sourceFolder + "fieldMergedWithWidget.pdf";
607+
String destFilename = destinationFolder + "mergeMergedFieldAndMergedFieldTest.pdf";
608+
String cmpFileName = sourceFolder + "cmp_mergeMergedFieldAndMergedFieldTest.pdf";
609+
610+
try (
611+
PdfWriter writer = new PdfWriter(destFilename);
612+
PdfDocument resultPdfDocument = new PdfDocument(writer);
613+
PdfReader reader1 = new PdfReader(srcFileName1);
614+
PdfDocument sourceDoc1 = new PdfDocument(reader1);) {
615+
PdfAcroForm.getAcroForm(resultPdfDocument, true);
616+
PdfPageFormCopier formCopier = new PdfPageFormCopier();
617+
618+
sourceDoc1.copyPagesTo(1, sourceDoc1.getNumberOfPages(), resultPdfDocument, formCopier);
619+
sourceDoc1.copyPagesTo(1, sourceDoc1.getNumberOfPages(), resultPdfDocument, formCopier);
620+
}
621+
622+
Assert.assertNull(new CompareTool().compareByContent(destFilename, cmpFileName, destinationFolder, "diff_"));
623+
}
624+
625+
@Test
626+
@LogMessages(messages = {
627+
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, count = 2)
628+
})
629+
public void mergeMergedFieldAndTwoWidgetsTest() throws IOException, InterruptedException {
630+
String srcFileName1 = sourceFolder + "fieldMergedWithWidget.pdf";
631+
String srcFileName2 = sourceFolder + "fieldTwoWidgets.pdf";
632+
String destFilename = destinationFolder + "mergeMergedFieldAndTwoWidgetsTest.pdf";
633+
String cmpFileName = sourceFolder + "cmp_mergeMergedFieldAndTwoWidgetsTest.pdf";
634+
635+
try (
636+
PdfWriter writer = new PdfWriter(destFilename);
637+
PdfDocument resultPdfDocument = new PdfDocument(writer);
638+
PdfReader reader1 = new PdfReader(srcFileName1);
639+
PdfDocument sourceDoc1 = new PdfDocument(reader1);
640+
PdfReader reader2 = new PdfReader(srcFileName2);
641+
PdfDocument sourceDoc2 = new PdfDocument(reader2);) {
642+
PdfAcroForm.getAcroForm(resultPdfDocument, true);
643+
PdfPageFormCopier formCopier = new PdfPageFormCopier();
644+
645+
sourceDoc1.copyPagesTo(1, sourceDoc1.getNumberOfPages(), resultPdfDocument, formCopier);
646+
sourceDoc2.copyPagesTo(1, sourceDoc2.getNumberOfPages(), resultPdfDocument, formCopier);
647+
}
648+
649+
Assert.assertNull(new CompareTool().compareByContent(destFilename, cmpFileName, destinationFolder, "diff_"));
650+
}
651+
652+
@Test
653+
@LogMessages(messages = {
654+
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD)
655+
})
656+
public void mergeTwoWidgetsAndMergedFieldTest() throws IOException, InterruptedException {
657+
String srcFileName1 = sourceFolder + "fieldMergedWithWidget.pdf";
658+
String srcFileName2 = sourceFolder + "fieldTwoWidgets.pdf";
659+
String destFilename = destinationFolder + "mergeTwoWidgetsAndMergedFieldTest.pdf";
660+
String cmpFileName = sourceFolder + "cmp_mergeTwoWidgetsAndMergedFieldTest.pdf";
661+
662+
try (
663+
PdfWriter writer = new PdfWriter(destFilename);
664+
PdfDocument resultPdfDocument = new PdfDocument(writer);
665+
PdfReader reader1 = new PdfReader(srcFileName1);
666+
PdfDocument sourceDoc1 = new PdfDocument(reader1);
667+
PdfReader reader2 = new PdfReader(srcFileName2);
668+
PdfDocument sourceDoc2 = new PdfDocument(reader2);) {
669+
PdfAcroForm.getAcroForm(resultPdfDocument, true);
670+
PdfPageFormCopier formCopier = new PdfPageFormCopier();
671+
672+
sourceDoc2.copyPagesTo(1, sourceDoc2.getNumberOfPages(), resultPdfDocument, formCopier);
673+
sourceDoc1.copyPagesTo(1, sourceDoc1.getNumberOfPages(), resultPdfDocument, formCopier);
674+
}
675+
676+
Assert.assertNull(new CompareTool().compareByContent(destFilename, cmpFileName, destinationFolder, "diff_"));
677+
}
678+
679+
@Test
680+
public void mergeTwoWidgetsAndTwoWidgetsTest() throws IOException, InterruptedException {
681+
String srcFileName2 = sourceFolder + "fieldTwoWidgets.pdf";
682+
String destFilename = destinationFolder + "mergeTwoWidgetsAndTwoWidgetsTest.pdf";
683+
String cmpFileName = sourceFolder + "cmp_mergeTwoWidgetsAndTwoWidgetsTest.pdf";
684+
685+
try (
686+
PdfWriter writer = new PdfWriter(destFilename);
687+
PdfDocument resultPdfDocument = new PdfDocument(writer);
688+
PdfReader reader2 = new PdfReader(srcFileName2);
689+
PdfDocument sourceDoc2 = new PdfDocument(reader2);) {
690+
PdfAcroForm.getAcroForm(resultPdfDocument, true);
691+
PdfPageFormCopier formCopier = new PdfPageFormCopier();
692+
693+
sourceDoc2.copyPagesTo(1, sourceDoc2.getNumberOfPages(), resultPdfDocument, formCopier);
694+
sourceDoc2.copyPagesTo(1, sourceDoc2.getNumberOfPages(), resultPdfDocument, formCopier);
695+
}
696+
697+
Assert.assertNull(new CompareTool().compareByContent(destFilename, cmpFileName, destinationFolder, "diff_"));
698+
}
599699
}
Binary file not shown.

hyph/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.itextpdf</groupId>
66
<artifactId>root</artifactId>
7-
<version>7.1.16</version>
7+
<version>7.1.17</version>
88
</parent>
99
<artifactId>hyph</artifactId>
1010
<name>iText 7 - hyph</name>

io/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.itextpdf</groupId>
66
<artifactId>root</artifactId>
7-
<version>7.1.16</version>
7+
<version>7.1.17</version>
88
</parent>
99
<artifactId>io</artifactId>
1010
<name>iText 7 - io</name>

0 commit comments

Comments
 (0)