@@ -41,6 +41,8 @@ source product.
41
41
42
42
*/
43
43
using System ;
44
+ using iText . Forms . Fields ;
45
+ using iText . Kernel . Colors ;
44
46
using iText . Kernel . Pdf ;
45
47
using iText . Kernel . Utils ;
46
48
using iText . Test ;
@@ -151,5 +153,61 @@ private static void FlattenFieldsAndCompare(String srcFile, String outFile) {
151
153
NUnit . Framework . Assert . Fail ( errorMessage ) ;
152
154
}
153
155
}
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
+ }
154
212
}
155
213
}
0 commit comments