Skip to content

Commit 7dde054

Browse files
rnadvodnyiText-CI
authored andcommitted
Fix copying fields during multiple page copying
DEVSIX-2187 Autoported commit. Original commit hash: [d2cdb45e1]
1 parent 3e81b6b commit 7dde054

13 files changed

+58
-21
lines changed

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

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ public virtual void CopyFieldsTest05() {
171171
/// <exception cref="System.IO.IOException"/>
172172
/// <exception cref="System.Exception"/>
173173
[NUnit.Framework.Test]
174-
[LogMessage(iText.IO.LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 4)]
174+
[LogMessage(iText.IO.LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 12)]
175175
public virtual void CopyMultipleSubfieldsTest01() {
176176
String srcFilename = sourceFolder + "copyMultipleSubfieldsTest01.pdf";
177177
String destFilename = destinationFolder + "copyMultipleSubfieldsTest01.pdf";
178178
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
179179
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
180180
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
181181
// copying the same page from the same document twice
182-
for (int i = 0; i < 2; ++i) {
182+
for (int i = 0; i < 4; ++i) {
183183
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
184184
}
185185
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
@@ -193,6 +193,50 @@ public virtual void CopyMultipleSubfieldsTest01() {
193193
, destinationFolder, "diff_"));
194194
}
195195

196+
/// <exception cref="System.IO.IOException"/>
197+
/// <exception cref="System.Exception"/>
198+
[NUnit.Framework.Test]
199+
[LogMessage(iText.IO.LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 2)]
200+
public virtual void CopyMultipleSubfieldsTest02() {
201+
String srcFilename = sourceFolder + "copyMultipleSubfieldsTest02.pdf";
202+
String destFilename = destinationFolder + "copyMultipleSubfieldsTest02.pdf";
203+
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
204+
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
205+
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
206+
// copying the same page from the same document twice
207+
for (int i = 0; i < 3; ++i) {
208+
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
209+
}
210+
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
211+
acroForm.GetField("text.3").SetValue("Text 3!");
212+
destDoc.Close();
213+
srcDoc.Close();
214+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyMultipleSubfieldsTest02.pdf"
215+
, destinationFolder, "diff_"));
216+
}
217+
218+
/// <exception cref="System.IO.IOException"/>
219+
/// <exception cref="System.Exception"/>
220+
[NUnit.Framework.Test]
221+
[LogMessage(iText.IO.LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 2)]
222+
public virtual void CopyMultipleSubfieldsTest03() {
223+
String srcFilename = sourceFolder + "copyMultipleSubfieldsTest03.pdf";
224+
String destFilename = destinationFolder + "copyMultipleSubfieldsTest03.pdf";
225+
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
226+
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
227+
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
228+
// copying the same page from the same document twice
229+
for (int i = 0; i < 3; ++i) {
230+
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
231+
}
232+
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
233+
acroForm.GetField("text_1").SetValue("Text 1!");
234+
destDoc.Close();
235+
srcDoc.Close();
236+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyMultipleSubfieldsTest03.pdf"
237+
, destinationFolder, "diff_"));
238+
}
239+
196240
/// <exception cref="System.IO.IOException"/>
197241
/// <exception cref="System.Exception"/>
198242
[NUnit.Framework.Test]

0 commit comments

Comments
 (0)