Skip to content

Commit 69d63ef

Browse files
yulian-gaponenkoiText-CI
authored andcommitted
Reinitialize form field appearance stream object on every field regeneration
First, appearance stream objects might be shared between different forms fields or other entities, if they are identical, so on regeneration we should not affect those other entities. Second, the resources of the streams and other entries in stream dictionaries are not shared between regenerations. It seems that this makes sense, because resources are completely rebuilt every time, and all other important entries in the appearance stream are updated on regeneration as well. DEVSIX-2374 Autoported commit. Original commit hash: [70def8325]
1 parent 2368898 commit 69d63ef

18 files changed

+50
-11
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,31 @@ public virtual void CopyMultipleSubfieldsTest03() {
237237
, destinationFolder, "diff_"));
238238
}
239239

240+
/// <exception cref="System.IO.IOException"/>
241+
/// <exception cref="System.Exception"/>
242+
[NUnit.Framework.Test]
243+
[LogMessage(iText.IO.LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 12)]
244+
public virtual void CopyMultipleSubfieldsSmartModeTest01() {
245+
String srcFilename = sourceFolder + "copyMultipleSubfieldsSmartModeTest01.pdf";
246+
String destFilename = destinationFolder + "copyMultipleSubfieldsSmartModeTest01.pdf";
247+
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
248+
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename).SetSmartMode(true));
249+
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
250+
// copying the same page from the same document twice
251+
for (int i = 0; i < 4; ++i) {
252+
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
253+
}
254+
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
255+
acroForm.GetField("text_1").SetValue("Text 1!");
256+
acroForm.GetField("text_2").SetValue("Text 2!");
257+
acroForm.GetField("text.3").SetValue("Text 3!");
258+
acroForm.GetField("text.4").SetValue("Text 4!");
259+
destDoc.Close();
260+
srcDoc.Close();
261+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyMultipleSubfieldsSmartModeTest01.pdf"
262+
, destinationFolder, "diff_"));
263+
}
264+
240265
/// <exception cref="System.IO.IOException"/>
241266
/// <exception cref="System.Exception"/>
242267
[NUnit.Framework.Test]

itext.tests/itext.forms.tests/itext/forms/PdfFormFieldTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,5 +565,27 @@ public virtual void MultilineFormFieldNewLineTest() {
565565
NUnit.Framework.Assert.Fail(errorMessage);
566566
}
567567
}
568+
569+
/// <exception cref="System.IO.IOException"/>
570+
/// <exception cref="System.Exception"/>
571+
[NUnit.Framework.Test]
572+
public virtual void FillFormWithSameEmptyObjsForAppearance() {
573+
String outPdf = destinationFolder + "fillFormWithSameEmptyObjsForAppearance.pdf";
574+
String cmpPdf = sourceFolder + "cmp_fillFormWithSameEmptyObjsForAppearance.pdf";
575+
PdfWriter writer = new PdfWriter(outPdf);
576+
PdfReader reader = new PdfReader(sourceFolder + "fillFormWithSameEmptyObjsForAppearance.pdf");
577+
PdfDocument pdfDoc = new PdfDocument(reader, writer);
578+
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, false);
579+
acroForm.GetField("text_1").SetValue("Text 1!");
580+
acroForm.GetField("text_2").SetValue("Text 2!");
581+
acroForm.GetField("text.3").SetValue("Text 3!");
582+
acroForm.GetField("text.4").SetValue("Text 4!");
583+
pdfDoc.Close();
584+
CompareTool compareTool = new CompareTool();
585+
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
586+
if (errorMessage != null) {
587+
NUnit.Framework.Assert.Fail(errorMessage);
588+
}
589+
}
568590
}
569591
}

0 commit comments

Comments
 (0)