diff --git a/forms/src/main/java/com/itextpdf/forms/PdfPageFormCopier.java b/forms/src/main/java/com/itextpdf/forms/PdfPageFormCopier.java index 7332092504..376f2478e8 100644 --- a/forms/src/main/java/com/itextpdf/forms/PdfPageFormCopier.java +++ b/forms/src/main/java/com/itextpdf/forms/PdfPageFormCopier.java @@ -335,7 +335,8 @@ private void addChildToExistingParent(PdfDictionary fieldDic, Set existi if (existingFields.contains(name)) { PdfArray kids = parent.getAsArray(PdfName.Kids); for (PdfObject kid : kids) { - if (((PdfDictionary) kid).get(PdfName.T).equals(fieldDic.get(PdfName.T))) { + if (((PdfDictionary) kid).get(PdfName.T) != null && + ((PdfDictionary) kid).get(PdfName.T).equals(fieldDic.get(PdfName.T))) { PdfFormField kidField = makeFormField(kid); PdfFormField field = makeFormField(fieldDic); if (kidField == null || field == null) { diff --git a/forms/src/test/java/com/itextpdf/forms/PdfFormCopyTest.java b/forms/src/test/java/com/itextpdf/forms/PdfFormCopyTest.java index 8683115e66..8e386ad985 100644 --- a/forms/src/test/java/com/itextpdf/forms/PdfFormCopyTest.java +++ b/forms/src/test/java/com/itextpdf/forms/PdfFormCopyTest.java @@ -696,4 +696,16 @@ public void mergeTwoWidgetsAndTwoWidgetsTest() throws IOException, InterruptedEx Assert.assertNull(new CompareTool().compareByContent(destFilename, cmpFileName, destinationFolder, "diff_")); } + + @Test + public void widgetContainsNoTEntryTest() throws IOException, InterruptedException { + String sourceFileName = sourceFolder + "fieldThreeWidgets.pdf"; + String destFileName = destinationFolder + "widgetContainsNoTEntryTest.pdf"; + String cmpFileName = sourceFolder + "cmp_widgetContainsNoTEntryTest.pdf"; + PdfDocument sourcePdfDocument = new PdfDocument(new PdfReader(sourceFileName)); + PdfDocument resultPdfDocument = new PdfDocument(new PdfWriter(destFileName)); + sourcePdfDocument.copyPagesTo(1, sourcePdfDocument.getNumberOfPages(), resultPdfDocument, new PdfPageFormCopier()); + resultPdfDocument.close(); + Assert.assertNull(new CompareTool().compareByContent(destFileName, cmpFileName, destinationFolder, "diff_")); + } } diff --git a/forms/src/test/resources/com/itextpdf/forms/PdfFormCopyTest/cmp_widgetContainsNoTEntryTest.pdf b/forms/src/test/resources/com/itextpdf/forms/PdfFormCopyTest/cmp_widgetContainsNoTEntryTest.pdf new file mode 100644 index 0000000000..bf42d7a59b Binary files /dev/null and b/forms/src/test/resources/com/itextpdf/forms/PdfFormCopyTest/cmp_widgetContainsNoTEntryTest.pdf differ diff --git a/forms/src/test/resources/com/itextpdf/forms/PdfFormCopyTest/fieldThreeWidgets.pdf b/forms/src/test/resources/com/itextpdf/forms/PdfFormCopyTest/fieldThreeWidgets.pdf new file mode 100644 index 0000000000..e5d8a6d99f Binary files /dev/null and b/forms/src/test/resources/com/itextpdf/forms/PdfFormCopyTest/fieldThreeWidgets.pdf differ