Skip to content

Commit ade8aec

Browse files
Add multiline fields with justification test
DEVSIX-1867 Autoported commit. Original commit hash: [6a3d9021cf]
1 parent 82ebe22 commit ade8aec

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
lines changed

itext.tests/itext.forms.tests/itext/forms/FormFieldFlatteningTest.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ source product.
4141
4242
*/
4343
using System;
44+
using iText.Forms.Fields;
45+
using iText.Kernel.Colors;
4446
using iText.Kernel.Pdf;
4547
using iText.Kernel.Utils;
4648
using iText.Test;
@@ -151,5 +153,61 @@ private static void FlattenFieldsAndCompare(String srcFile, String outFile) {
151153
NUnit.Framework.Assert.Fail(errorMessage);
152154
}
153155
}
156+
157+
/// <exception cref="System.IO.IOException"/>
158+
/// <exception cref="System.Exception"/>
159+
[NUnit.Framework.Test]
160+
public virtual void FieldsJustificationTest01() {
161+
FillTextFieldsThenFlattenThenCompare("fieldsJustificationTest01");
162+
}
163+
164+
/// <exception cref="System.IO.IOException"/>
165+
/// <exception cref="System.Exception"/>
166+
[NUnit.Framework.Test]
167+
public virtual void FieldsJustificationTest02() {
168+
FillTextFieldsThenFlattenThenCompare("fieldsJustificationTest02");
169+
}
170+
171+
/// <exception cref="System.IO.IOException"/>
172+
/// <exception cref="System.Exception"/>
173+
private static void FillTextFieldsThenFlattenThenCompare(String testName) {
174+
String src = sourceFolder + "src_" + testName + ".pdf";
175+
String dest = destinationFolder + testName + ".pdf";
176+
String cmp = sourceFolder + "cmp_" + testName + ".pdf";
177+
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
178+
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
179+
foreach (PdfFormField field in form.GetFormFields().Values) {
180+
if (field is PdfTextFormField) {
181+
String newValue;
182+
if (field.IsMultiline()) {
183+
newValue = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
184+
}
185+
else {
186+
newValue = "HELLO!";
187+
}
188+
int? justification = field.GetJustification();
189+
if (null == justification || 0 == (int)justification) {
190+
field.SetBackgroundColor(new DeviceRgb(255, 200, 200));
191+
}
192+
else {
193+
// reddish
194+
if (1 == (int)justification) {
195+
field.SetBackgroundColor(new DeviceRgb(200, 255, 200));
196+
}
197+
else {
198+
// greenish
199+
if (2 == (int)justification) {
200+
field.SetBackgroundColor(new DeviceRgb(200, 200, 255));
201+
}
202+
}
203+
}
204+
// blueish
205+
field.SetValue(newValue);
206+
}
207+
}
208+
form.FlattenFields();
209+
doc.Close();
210+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder, "diff_"));
211+
}
154212
}
155213
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f59b9ab6dc56bb906680aea70788ebd1857cdb38
1+
6a3d9021cfabe03aaf5ee7851ce08968e95af1a4

0 commit comments

Comments
 (0)