Skip to content

Commit 73f53a7

Browse files
AnhelinaMiText-CI
authored andcommitted
Handle NPE on CopyPagesTo
DEVSIX-6298 Autoported commit. Original commit hash: [30c6c9e88]
1 parent 402aac4 commit 73f53a7

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

itext.tests/itext.forms.tests/itext/forms/PdfFormCopyTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,5 +578,19 @@ public virtual void MergeTwoWidgetsAndTwoWidgetsTest() {
578578
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, cmpFileName, destinationFolder
579579
, "diff_"));
580580
}
581+
582+
[NUnit.Framework.Test]
583+
public virtual void WidgetContainsNoTEntryTest() {
584+
String sourceFileName = sourceFolder + "fieldThreeWidgets.pdf";
585+
String destFileName = destinationFolder + "widgetContainsNoTEntryTest.pdf";
586+
String cmpFileName = sourceFolder + "cmp_widgetContainsNoTEntryTest.pdf";
587+
PdfDocument sourcePdfDocument = new PdfDocument(new PdfReader(sourceFileName));
588+
PdfDocument resultPdfDocument = new PdfDocument(new PdfWriter(destFileName));
589+
sourcePdfDocument.CopyPagesTo(1, sourcePdfDocument.GetNumberOfPages(), resultPdfDocument, new PdfPageFormCopier
590+
());
591+
resultPdfDocument.Close();
592+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFileName, cmpFileName, destinationFolder
593+
, "diff_"));
594+
}
581595
}
582596
}
Binary file not shown.

itext/itext.forms/itext/forms/PdfPageFormCopier.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ private void AddChildToExistingParent(PdfDictionary fieldDic, ICollection<String
315315
if (existingFields.Contains(name)) {
316316
PdfArray kids = parent.GetAsArray(PdfName.Kids);
317317
foreach (PdfObject kid in kids) {
318-
if (((PdfDictionary)kid).Get(PdfName.T).Equals(fieldDic.Get(PdfName.T))) {
318+
if (((PdfDictionary)kid).Get(PdfName.T) != null && ((PdfDictionary)kid).Get(PdfName.T).Equals(fieldDic.Get
319+
(PdfName.T))) {
319320
PdfFormField kidField = MakeFormField(kid);
320321
PdfFormField field = MakeFormField(fieldDic);
321322
if (kidField == null || field == null) {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22b28c21a6e4eba260a7470f015d7391d63cfbec
1+
30c6c9e883a50dae6adb0bfe884414f0d682cc31

0 commit comments

Comments
 (0)