@@ -156,4 +156,49 @@ private static void flattenFieldsAndCompare(String srcFile, String outFile) thro
156
156
Assert .fail (errorMessage );
157
157
}
158
158
}
159
+
160
+ @ Test
161
+ public void fieldsJustificationTest01 () throws IOException , InterruptedException {
162
+ fillTextFieldsThenFlattenThenCompare ("fieldsJustificationTest01" );
163
+ }
164
+
165
+ @ Test
166
+ public void fieldsJustificationTest02 () throws IOException , InterruptedException {
167
+ fillTextFieldsThenFlattenThenCompare ("fieldsJustificationTest02" );
168
+ }
169
+
170
+ private static void fillTextFieldsThenFlattenThenCompare (String testName ) throws IOException , InterruptedException {
171
+ String src = sourceFolder + "src_" + testName + ".pdf" ;
172
+ String dest = destinationFolder + testName + ".pdf" ;
173
+ String cmp = sourceFolder + "cmp_" + testName + ".pdf" ;
174
+
175
+ PdfDocument doc = new PdfDocument (new PdfReader (src ), new PdfWriter (dest ));
176
+ PdfAcroForm form = PdfAcroForm .getAcroForm (doc , true );
177
+ for (PdfFormField field : form .getFormFields ().values ()) {
178
+ if (field instanceof PdfTextFormField ) {
179
+ String newValue ;
180
+ if (field .isMultiline ()) {
181
+ newValue = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." ;
182
+ } else {
183
+ newValue = "HELLO!" ;
184
+ }
185
+
186
+ Integer justification = field .getJustification ();
187
+ if (null == justification || 0 == (int ) justification ) {
188
+ field .setBackgroundColor (new DeviceRgb (255 , 200 , 200 )); // reddish
189
+ } else if (1 == (int ) justification ) {
190
+ field .setBackgroundColor (new DeviceRgb (200 , 255 , 200 )); // greenish
191
+ } else if (2 == (int ) justification ) {
192
+ field .setBackgroundColor (new DeviceRgb (200 , 200 , 255 )); // blueish
193
+ }
194
+
195
+ field .setValue (newValue );
196
+ }
197
+ }
198
+ form .flattenFields ();
199
+ doc .close ();
200
+
201
+
202
+ Assert .assertNull (new CompareTool ().compareByContent (dest , cmp , destinationFolder , "diff_" ));
203
+ }
159
204
}
0 commit comments