@@ -41,16 +41,11 @@ source product.
41414242*/
4343using System ;
44- using System . IO ;
45- using iText . Forms ;
4644using iText . Html2pdf ;
4745using iText . Kernel ;
48- using iText . Kernel . Pdf ;
49- using iText . Kernel . Utils ;
50- using iText . Test ;
5146
5247namespace iText . Html2pdf . Element {
53- public class TaggedPdfFormTest : ExtendedITextTest {
48+ public class TaggedPdfFormTest : ExtendedHtmlConversionITextTest {
5449 public static readonly String sourceFolder = iText . Test . TestUtil . GetParentProjectDirectory ( NUnit . Framework . TestContext
5550 . CurrentContext . TestDirectory ) + "/resources/itext/html2pdf/element/TaggedPdfFormTest/" ;
5651
@@ -64,110 +59,73 @@ public static void BeforeClass() {
6459
6560 [ NUnit . Framework . Test ]
6661 public virtual void SimpleTextFieldTagged ( ) {
67- RunTest ( "simpleTextFieldTagged" ) ;
62+ ConvertToPdfAcroformFlattenAndCompare ( "simpleTextField" , sourceFolder , destinationFolder , true ) ;
6863 }
6964
7065 [ NUnit . Framework . Test ]
7166 public virtual void SimpleTextareaTagged ( ) {
72- RunTest ( "simpleTextareaTagged" ) ;
67+ ConvertToPdfAcroformFlattenAndCompare ( "simpleTextarea" , sourceFolder , destinationFolder , true ) ;
7368 }
7469
7570 [ NUnit . Framework . Test ]
7671 public virtual void SimpleButtonTagged ( ) {
77- RunTest ( "simpleButtonTagged" ) ;
72+ ConvertToPdfAcroformFlattenAndCompare ( "simpleButton" , sourceFolder , destinationFolder , true ) ;
7873 }
7974
8075 [ NUnit . Framework . Test ]
8176 public virtual void SimpleLabelTagged ( ) {
82- RunTest ( "simpleLabelTagged" ) ;
77+ ConvertToPdfAcroformFlattenAndCompare ( "simpleLabel" , sourceFolder , destinationFolder , true ) ;
8378 }
8479
8580 [ NUnit . Framework . Test ]
8681 public virtual void SimpleCheckboxTagged ( ) {
87- RunTest ( "simpleCheckboxTagged" ) ;
82+ ConvertToPdfAcroformFlattenAndCompare ( "simpleCheckbox" , sourceFolder , destinationFolder , true ) ;
8883 }
8984
9085 [ NUnit . Framework . Test ]
9186 [ NUnit . Framework . Ignore ( "DEVSIX-1901" ) ]
9287 public virtual void SimpleSelectTagged ( ) {
93- RunTest ( "simpleSelectTagged" ) ;
88+ ConvertToPdfAcroformFlattenAndCompare ( "simpleSelect" , sourceFolder , destinationFolder , true ) ;
9489 }
9590
9691 [ NUnit . Framework . Test ]
9792 [ NUnit . Framework . Ignore ( "DEVSIX-1901" ) ]
9893 public virtual void ListBoxSelectTagged ( ) {
99- RunTest ( "listBoxSelectTagged" ) ;
94+ ConvertToPdfAcroformFlattenAndCompare ( "listBoxSelect" , sourceFolder , destinationFolder , true ) ;
10095 }
10196
10297 [ NUnit . Framework . Test ]
10398 [ NUnit . Framework . Ignore ( "DEVSIX-1901" ) ]
10499 public virtual void ListBoxOptGroupSelectTagged ( ) {
105- RunTest ( "listBoxOptGroupSelectTagged" ) ;
100+ ConvertToPdfAcroformFlattenAndCompare ( "listBoxOptGroupSelect" , sourceFolder , destinationFolder , true ) ;
106101 }
107102
108103 [ NUnit . Framework . Test ]
109104 [ NUnit . Framework . Ignore ( "DEVSIX-1901" ) ]
110105 public virtual void SimpleRadioFormTagged ( ) {
111- RunTest ( "simpleRadioFormTagged" ) ;
106+ ConvertToPdfAcroformFlattenAndCompare ( "simpleRadioForm" , sourceFolder , destinationFolder , true ) ;
112107 }
113108
114109 [ NUnit . Framework . Test ]
115110 [ NUnit . Framework . Ignore ( "DEVSIX-980. DefaultHtmlProcessor ERROR No worker found for tag datalist" ) ]
116111 public virtual void DataListFormTagged ( ) {
117- RunTest ( "dataListFormTagged" ) ;
112+ ConvertToPdfAcroformFlattenAndCompare ( "dataListForm" , sourceFolder , destinationFolder , true ) ;
118113 }
119114
120115 [ NUnit . Framework . Test ]
121116 public virtual void FieldSetFormTagged ( ) {
122- RunTest ( "fieldSetFormTagged" ) ;
117+ ConvertToPdfAcroformFlattenAndCompare ( "fieldSetForm" , sourceFolder , destinationFolder , true ) ;
123118 }
124119
125120 [ NUnit . Framework . Test ]
126121 public virtual void InputFormPrematureFlush ( ) {
127122 NUnit . Framework . Assert . That ( ( ) => {
128123 // TODO DEVSIX-4601
129124 // exception is thrown on "convert tagged PDF with acroform" stage
130- RunTest ( "inputFormPrematureFlush" ) ;
125+ ConvertToPdfAcroformFlattenAndCompare ( "inputFormPrematureFlush" , sourceFolder , destinationFolder , true ) ;
131126 }
132127 , NUnit . Framework . Throws . InstanceOf < PdfException > ( ) . With . Message . EqualTo ( PdfException . TagStructureFlushingFailedItMightBeCorrupted ) )
133128;
134129 }
135-
136- private void RunTest ( String name ) {
137- String htmlPath = sourceFolder + name + ".html" ;
138- String outTaggedPdfPath = destinationFolder + name + ".pdf" ;
139- String outTaggedPdfPathAcro = destinationFolder + name + "_acro.pdf" ;
140- String outTaggedPdfPathFlatted = destinationFolder + name + "_acro_flatten.pdf" ;
141- String cmpPdfPath = sourceFolder + "cmp_" + name + ".pdf" ;
142- String cmpPdfPathAcro = sourceFolder + "cmp_" + name + "_acro.pdf" ;
143- String cmpPdfPathAcroFlatten = sourceFolder + "cmp_" + name + "_acro_flatten.pdf" ;
144- String diff1 = "diff1_" + name ;
145- String diff2 = "diff2_" + name ;
146- String diff3 = "diff3_" + name ;
147- //convert tagged PDF without acroform (from html with form elements)
148- PdfWriter taggedWriter = new PdfWriter ( outTaggedPdfPath ) ;
149- PdfDocument pdfTagged = new PdfDocument ( taggedWriter ) ;
150- pdfTagged . SetTagged ( ) ;
151- HtmlConverter . ConvertToPdf ( new FileStream ( htmlPath , FileMode . Open , FileAccess . Read ) , pdfTagged ) ;
152- //convert tagged PDF with acroform
153- PdfWriter taggedWriterAcro = new PdfWriter ( outTaggedPdfPathAcro ) ;
154- PdfDocument pdfTaggedAcro = new PdfDocument ( taggedWriterAcro ) ;
155- pdfTaggedAcro . SetTagged ( ) ;
156- ConverterProperties converterPropertiesAcro = new ConverterProperties ( ) ;
157- converterPropertiesAcro . SetCreateAcroForm ( true ) ;
158- HtmlConverter . ConvertToPdf ( new FileStream ( htmlPath , FileMode . Open , FileAccess . Read ) , pdfTaggedAcro , converterPropertiesAcro
159- ) ;
160- //flatted created tagged PDF with acroform
161- PdfDocument document = new PdfDocument ( new PdfReader ( outTaggedPdfPathAcro ) , new PdfWriter ( outTaggedPdfPathFlatted
162- ) ) ;
163- PdfAcroForm . GetAcroForm ( document , false ) . FlattenFields ( ) ;
164- document . Close ( ) ;
165- NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outTaggedPdfPath , cmpPdfPath , destinationFolder
166- , diff1 ) ) ;
167- NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outTaggedPdfPathAcro , cmpPdfPathAcro , destinationFolder
168- , diff2 ) ) ;
169- NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outTaggedPdfPathFlatted , cmpPdfPathAcroFlatten
170- , destinationFolder , diff3 ) ) ;
171- }
172130 }
173131}
0 commit comments