@@ -42,31 +42,23 @@ This file is part of the iText (R) project.
4242 */
4343package com .itextpdf .html2pdf .element ;
4444
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 ;
4946import 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 ;
5547import com .itextpdf .test .annotations .type .IntegrationTest ;
56- import org .junit .Assert ;
48+
49+ import javax .xml .parsers .ParserConfigurationException ;
5750import org .junit .BeforeClass ;
5851import org .junit .Ignore ;
5952import org .junit .Rule ;
6053import org .junit .Test ;
6154import org .junit .experimental .categories .Category ;
6255import org .junit .rules .ExpectedException ;
6356
64- import java .io .FileInputStream ;
6557import java .io .IOException ;
58+ import org .xml .sax .SAXException ;
6659
6760@ Category (IntegrationTest .class )
68- public class TaggedPdfFormTest extends ExtendedITextTest {
69-
61+ public class TaggedPdfFormTest extends ExtendedHtmlConversionITextTest {
7062
7163 public static final String sourceFolder = "./src/test/resources/com/itextpdf/html2pdf/element/TaggedPdfFormTest/" ;
7264 public static final String destinationFolder = "./target/test/com/itextpdf/html2pdf/element/TaggedPdfFormTest/" ;
@@ -80,107 +72,86 @@ public static void beforeClass() {
8072 public ExpectedException junitExpectedException = ExpectedException .none ();
8173
8274 @ 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 );
8578 }
8679
8780 @ 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 );
9084 }
9185
9286 @ 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 );
9590 }
9691
9792 @ 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 );
10096 }
10197
10298 @ 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 );
105102 }
106103
107104 @ Test
108105 @ 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 );
111109 }
112110
113111 @ Test
114112 @ 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 );
117116 }
118117
119118 @ Test
120119 @ 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 );
123124 }
124125
125126 @ Test
126127 @ 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 );
129131 }
130132
131133 @ Test
132134 @ 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 );
135138 }
136139
137140 @ 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 );
140144 }
141145
142146 @ Test
143147 // TODO DEVSIX-4601
144148 // 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 {
146151 junitExpectedException .expect (PdfException .class );
147152 junitExpectedException .expectMessage (PdfException .TagStructureFlushingFailedItMightBeCorrupted );
148- runTest ("inputFormPrematureFlush" );
149- }
150153
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 );
185156 }
186157}
0 commit comments