@@ -55,39 +55,25 @@ public class FormFieldFlatteningTest : ExtendedITextTest {
55
55
56
56
[ NUnit . Framework . OneTimeSetUp ]
57
57
public static void BeforeClass ( ) {
58
- CreateDestinationFolder ( destinationFolder ) ;
58
+ CreateOrClearDestinationFolder ( destinationFolder ) ;
59
59
}
60
60
61
61
/// <exception cref="System.IO.IOException"/>
62
62
/// <exception cref="System.Exception"/>
63
63
[ NUnit . Framework . Test ]
64
64
public virtual void FormFlatteningTest01 ( ) {
65
- String srcFilename = sourceFolder + "formFlatteningSource.pdf" ;
66
- String filename = destinationFolder + "formFlatteningTest01.pdf" ;
67
- PdfDocument doc = new PdfDocument ( new PdfReader ( srcFilename ) , new PdfWriter ( filename ) ) ;
68
- PdfAcroForm form = PdfAcroForm . GetAcroForm ( doc , true ) ;
69
- form . FlattenFields ( ) ;
70
- doc . Close ( ) ;
71
- NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( filename , sourceFolder + "cmp_formFlatteningTest01.pdf"
72
- , destinationFolder , "diff_" ) ) ;
65
+ String srcFilename = "formFlatteningSource.pdf" ;
66
+ String filename = "formFlatteningTest01.pdf" ;
67
+ FlattenFieldsAndCompare ( srcFilename , filename ) ;
73
68
}
74
69
75
70
/// <exception cref="System.IO.IOException"/>
76
71
/// <exception cref="System.Exception"/>
77
72
[ NUnit . Framework . Test ]
78
73
public virtual void FormFlatteningChoiceFieldTest01 ( ) {
79
- String srcFilename = sourceFolder + "formFlatteningSourceChoiceField.pdf" ;
80
- String filename = destinationFolder + "formFlatteningChoiceFieldTest01.pdf" ;
81
- PdfDocument doc = new PdfDocument ( new PdfReader ( srcFilename ) , new PdfWriter ( filename ) ) ;
82
- PdfAcroForm form = PdfAcroForm . GetAcroForm ( doc , true ) ;
83
- form . FlattenFields ( ) ;
84
- doc . Close ( ) ;
85
- CompareTool compareTool = new CompareTool ( ) ;
86
- String errorMessage = compareTool . CompareByContent ( filename , sourceFolder + "cmp_formFlatteningChoiceFieldTest01.pdf"
87
- , destinationFolder , "diff_" ) ;
88
- if ( errorMessage != null ) {
89
- NUnit . Framework . Assert . Fail ( errorMessage ) ;
90
- }
74
+ String srcFilename = "formFlatteningSourceChoiceField.pdf" ;
75
+ String filename = "formFlatteningChoiceFieldTest01.pdf" ;
76
+ FlattenFieldsAndCompare ( srcFilename , filename ) ;
91
77
}
92
78
93
79
/// <exception cref="System.IO.IOException"/>
@@ -104,5 +90,66 @@ public virtual void MultiLineFormFieldClippingTest() {
104
90
doc . Close ( ) ;
105
91
NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( dest , cmp , destinationFolder , "diff_" ) ) ;
106
92
}
93
+
94
+ /// <exception cref="System.IO.IOException"/>
95
+ /// <exception cref="System.Exception"/>
96
+ [ NUnit . Framework . Test ]
97
+ public virtual void RotatedFieldAppearanceTest01 ( ) {
98
+ String srcFilename = "src_rotatedFieldAppearanceTest01.pdf" ;
99
+ String filename = "rotatedFieldAppearanceTest01.pdf" ;
100
+ FlattenFieldsAndCompare ( srcFilename , filename ) ;
101
+ }
102
+
103
+ /// <exception cref="System.IO.IOException"/>
104
+ /// <exception cref="System.Exception"/>
105
+ [ NUnit . Framework . Test ]
106
+ public virtual void RotatedFieldAppearanceTest02 ( ) {
107
+ String srcFilename = "src_rotatedFieldAppearanceTest02.pdf" ;
108
+ String filename = "rotatedFieldAppearanceTest02.pdf" ;
109
+ FlattenFieldsAndCompare ( srcFilename , filename ) ;
110
+ }
111
+
112
+ /// <exception cref="System.IO.IOException"/>
113
+ /// <exception cref="System.Exception"/>
114
+ [ NUnit . Framework . Test ]
115
+ public virtual void DegeneratedRectTest01 ( ) {
116
+ String srcFilename = "src_degeneratedRectTest01.pdf" ;
117
+ String filename = "degeneratedRectTest01.pdf" ;
118
+ FlattenFieldsAndCompare ( srcFilename , filename ) ;
119
+ }
120
+
121
+ /// <exception cref="System.IO.IOException"/>
122
+ /// <exception cref="System.Exception"/>
123
+ [ NUnit . Framework . Test ]
124
+ public virtual void DegeneratedRectTest02 ( ) {
125
+ String srcFilename = "src_degeneratedRectTest02.pdf" ;
126
+ String filename = "degeneratedRectTest02.pdf" ;
127
+ FlattenFieldsAndCompare ( srcFilename , filename ) ;
128
+ }
129
+
130
+ /// <exception cref="System.IO.IOException"/>
131
+ /// <exception cref="System.Exception"/>
132
+ [ NUnit . Framework . Test ]
133
+ public virtual void ScaledRectTest01 ( ) {
134
+ String srcFilename = "src_scaledRectTest01.pdf" ;
135
+ String filename = "scaledRectTest01.pdf" ;
136
+ FlattenFieldsAndCompare ( srcFilename , filename ) ;
137
+ }
138
+
139
+ /// <exception cref="System.IO.IOException"/>
140
+ /// <exception cref="System.Exception"/>
141
+ private static void FlattenFieldsAndCompare ( String srcFile , String outFile ) {
142
+ PdfReader reader = new PdfReader ( sourceFolder + srcFile ) ;
143
+ PdfWriter writer = new PdfWriter ( destinationFolder + outFile ) ;
144
+ PdfDocument document = new PdfDocument ( reader , writer ) ;
145
+ PdfAcroForm . GetAcroForm ( document , false ) . FlattenFields ( ) ;
146
+ document . Close ( ) ;
147
+ CompareTool compareTool = new CompareTool ( ) ;
148
+ String errorMessage = compareTool . CompareByContent ( destinationFolder + outFile , sourceFolder + "cmp_" + outFile
149
+ , destinationFolder , "diff_" ) ;
150
+ if ( errorMessage != null ) {
151
+ NUnit . Framework . Assert . Fail ( errorMessage ) ;
152
+ }
153
+ }
107
154
}
108
155
}
0 commit comments