@@ -42,31 +42,23 @@ This file is part of the iText (R) project.
42
42
*/
43
43
package com .itextpdf .html2pdf .element ;
44
44
45
-
46
- import com .itextpdf .forms .PdfAcroForm ;
47
- import com .itextpdf .html2pdf .ConverterProperties ;
48
- import com .itextpdf .html2pdf .HtmlConverter ;
45
+ import com .itextpdf .html2pdf .ExtendedHtmlConversionITextTest ;
49
46
import com .itextpdf .kernel .PdfException ;
50
- import com .itextpdf .kernel .pdf .PdfDocument ;
51
- import com .itextpdf .kernel .pdf .PdfReader ;
52
- import com .itextpdf .kernel .pdf .PdfWriter ;
53
- import com .itextpdf .kernel .utils .CompareTool ;
54
- import com .itextpdf .test .ExtendedITextTest ;
55
47
import com .itextpdf .test .annotations .type .IntegrationTest ;
56
- import org .junit .Assert ;
48
+
49
+ import javax .xml .parsers .ParserConfigurationException ;
57
50
import org .junit .BeforeClass ;
58
51
import org .junit .Ignore ;
59
52
import org .junit .Rule ;
60
53
import org .junit .Test ;
61
54
import org .junit .experimental .categories .Category ;
62
55
import org .junit .rules .ExpectedException ;
63
56
64
- import java .io .FileInputStream ;
65
57
import java .io .IOException ;
58
+ import org .xml .sax .SAXException ;
66
59
67
60
@ Category (IntegrationTest .class )
68
- public class TaggedPdfFormTest extends ExtendedITextTest {
69
-
61
+ public class TaggedPdfFormTest extends ExtendedHtmlConversionITextTest {
70
62
71
63
public static final String sourceFolder = "./src/test/resources/com/itextpdf/html2pdf/element/TaggedPdfFormTest/" ;
72
64
public static final String destinationFolder = "./target/test/com/itextpdf/html2pdf/element/TaggedPdfFormTest/" ;
@@ -80,107 +72,86 @@ public static void beforeClass() {
80
72
public ExpectedException junitExpectedException = ExpectedException .none ();
81
73
82
74
@ Test
83
- public void simpleTextFieldTagged () throws IOException , InterruptedException {
84
- runTest ("simpleTextFieldTagged" );
75
+ public void simpleTextFieldTagged ()
76
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
77
+ convertToPdfAcroformFlattenAndCompare ("simpleTextField" , sourceFolder , destinationFolder , true );
85
78
}
86
79
87
80
@ Test
88
- public void simpleTextareaTagged () throws IOException , InterruptedException {
89
- runTest ("simpleTextareaTagged" );
81
+ public void simpleTextareaTagged ()
82
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
83
+ convertToPdfAcroformFlattenAndCompare ("simpleTextarea" , sourceFolder , destinationFolder , true );
90
84
}
91
85
92
86
@ Test
93
- public void simpleButtonTagged () throws IOException , InterruptedException {
94
- runTest ("simpleButtonTagged" );
87
+ public void simpleButtonTagged ()
88
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
89
+ convertToPdfAcroformFlattenAndCompare ("simpleButton" , sourceFolder , destinationFolder , true );
95
90
}
96
91
97
92
@ Test
98
- public void simpleLabelTagged () throws IOException , InterruptedException {
99
- runTest ("simpleLabelTagged" );
93
+ public void simpleLabelTagged ()
94
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
95
+ convertToPdfAcroformFlattenAndCompare ("simpleLabel" , sourceFolder , destinationFolder , true );
100
96
}
101
97
102
98
@ Test
103
- public void simpleCheckboxTagged () throws IOException , InterruptedException {
104
- runTest ("simpleCheckboxTagged" );
99
+ public void simpleCheckboxTagged ()
100
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
101
+ convertToPdfAcroformFlattenAndCompare ("simpleCheckbox" , sourceFolder , destinationFolder , true );
105
102
}
106
103
107
104
@ Test
108
105
@ Ignore ("DEVSIX-1901" )
109
- public void simpleSelectTagged () throws IOException , InterruptedException {
110
- runTest ("simpleSelectTagged" );
106
+ public void simpleSelectTagged ()
107
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
108
+ convertToPdfAcroformFlattenAndCompare ("simpleSelect" , sourceFolder , destinationFolder , true );
111
109
}
112
110
113
111
@ Test
114
112
@ Ignore ("DEVSIX-1901" )
115
- public void listBoxSelectTagged () throws IOException , InterruptedException {
116
- runTest ("listBoxSelectTagged" );
113
+ public void listBoxSelectTagged ()
114
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
115
+ convertToPdfAcroformFlattenAndCompare ("listBoxSelect" , sourceFolder , destinationFolder , true );
117
116
}
118
117
119
118
@ Test
120
119
@ Ignore ("DEVSIX-1901" )
121
- public void listBoxOptGroupSelectTagged () throws IOException , InterruptedException {
122
- runTest ("listBoxOptGroupSelectTagged" );
120
+ public void listBoxOptGroupSelectTagged ()
121
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
122
+ convertToPdfAcroformFlattenAndCompare ("listBoxOptGroupSelect" , sourceFolder ,
123
+ destinationFolder , true );
123
124
}
124
125
125
126
@ Test
126
127
@ Ignore ("DEVSIX-1901" )
127
- public void simpleRadioFormTagged () throws IOException , InterruptedException {
128
- runTest ("simpleRadioFormTagged" );
128
+ public void simpleRadioFormTagged ()
129
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
130
+ convertToPdfAcroformFlattenAndCompare ("simpleRadioForm" , sourceFolder , destinationFolder , true );
129
131
}
130
132
131
133
@ Test
132
134
@ Ignore ("DEVSIX-980. DefaultHtmlProcessor ERROR No worker found for tag datalist" )
133
- public void dataListFormTagged () throws IOException , InterruptedException {
134
- runTest ("dataListFormTagged" );
135
+ public void dataListFormTagged ()
136
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
137
+ convertToPdfAcroformFlattenAndCompare ("dataListForm" , sourceFolder , destinationFolder , true );
135
138
}
136
139
137
140
@ Test
138
- public void fieldSetFormTagged () throws IOException , InterruptedException {
139
- runTest ("fieldSetFormTagged" );
141
+ public void fieldSetFormTagged ()
142
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
143
+ convertToPdfAcroformFlattenAndCompare ("fieldSetForm" , sourceFolder , destinationFolder , true );
140
144
}
141
145
142
146
@ Test
143
147
// TODO DEVSIX-4601
144
148
// exception is thrown on "convert tagged PDF with acroform" stage
145
- public void inputFormPrematureFlush () throws IOException , InterruptedException {
149
+ public void inputFormPrematureFlush ()
150
+ throws IOException , InterruptedException , ParserConfigurationException , SAXException {
146
151
junitExpectedException .expect (PdfException .class );
147
152
junitExpectedException .expectMessage (PdfException .TagStructureFlushingFailedItMightBeCorrupted );
148
- runTest ("inputFormPrematureFlush" );
149
- }
150
153
151
- private void runTest (String name ) throws IOException , InterruptedException {
152
- String htmlPath = sourceFolder + name + ".html" ;
153
- String outTaggedPdfPath = destinationFolder + name + ".pdf" ;
154
- String outTaggedPdfPathAcro = destinationFolder + name + "_acro.pdf" ;
155
- String outTaggedPdfPathFlatted = destinationFolder + name + "_acro_flatten.pdf" ;
156
- String cmpPdfPath = sourceFolder + "cmp_" + name + ".pdf" ;
157
- String cmpPdfPathAcro = sourceFolder + "cmp_" + name + "_acro.pdf" ;
158
- String cmpPdfPathAcroFlatten = sourceFolder + "cmp_" + name + "_acro_flatten.pdf" ;
159
- String diff1 = "diff1_" + name ;
160
- String diff2 = "diff2_" + name ;
161
- String diff3 = "diff3_" + name ;
162
-
163
- //convert tagged PDF without acroform (from html with form elements)
164
- PdfWriter taggedWriter = new PdfWriter (outTaggedPdfPath );
165
- PdfDocument pdfTagged = new PdfDocument (taggedWriter );
166
- pdfTagged .setTagged ();
167
- HtmlConverter .convertToPdf (new FileInputStream (htmlPath ), pdfTagged );
168
-
169
- //convert tagged PDF with acroform
170
- PdfWriter taggedWriterAcro = new PdfWriter (outTaggedPdfPathAcro );
171
- PdfDocument pdfTaggedAcro = new PdfDocument (taggedWriterAcro );
172
- pdfTaggedAcro .setTagged ();
173
- ConverterProperties converterPropertiesAcro = new ConverterProperties ();
174
- converterPropertiesAcro .setCreateAcroForm (true );
175
- HtmlConverter .convertToPdf (new FileInputStream (htmlPath ), pdfTaggedAcro , converterPropertiesAcro );
176
-
177
- //flatted created tagged PDF with acroform
178
- PdfDocument document = new PdfDocument (new PdfReader (outTaggedPdfPathAcro ), new PdfWriter (outTaggedPdfPathFlatted ));
179
- PdfAcroForm .getAcroForm (document , false ).flattenFields ();
180
- document .close ();
181
-
182
- Assert .assertNull (new CompareTool ().compareByContent (outTaggedPdfPath , cmpPdfPath , destinationFolder , diff1 ));
183
- Assert .assertNull (new CompareTool ().compareByContent (outTaggedPdfPathAcro , cmpPdfPathAcro , destinationFolder , diff2 ));
184
- Assert .assertNull (new CompareTool ().compareByContent (outTaggedPdfPathFlatted , cmpPdfPathAcroFlatten , destinationFolder , diff3 ));
154
+ convertToPdfAcroformFlattenAndCompare ("inputFormPrematureFlush" ,
155
+ sourceFolder , destinationFolder , true );
185
156
}
186
157
}
0 commit comments