@@ -42,169 +42,103 @@ This file is part of the iText (R) project.
42
42
*/
43
43
package com .itextpdf .html2pdf ;
44
44
45
- import com .itextpdf .html2pdf .attach .IHtmlProcessor ;
46
- import com .itextpdf .html2pdf .attach .impl .DefaultHtmlProcessor ;
47
- import com .itextpdf .html2pdf .resolver .font .DefaultFontProvider ;
48
45
import com .itextpdf .html2pdf .logs .Html2PdfLogMessageConstant ;
49
- import com .itextpdf .io .logs .IoLogMessageConstant ;
50
- import com .itextpdf .io .util .UrlUtil ;
51
- import com .itextpdf .kernel .pdf .PdfDocument ;
52
- import com .itextpdf .kernel .pdf .PdfWriter ;
53
- import com .itextpdf .kernel .utils .CompareTool ;
54
- import com .itextpdf .layout .Document ;
55
- import com .itextpdf .layout .font .FontProvider ;
56
- import com .itextpdf .styledxmlparser .IXmlParser ;
57
46
import com .itextpdf .styledxmlparser .logs .StyledXmlParserLogMessageConstant ;
58
- import com .itextpdf .styledxmlparser .css .media .MediaDeviceDescription ;
59
- import com .itextpdf .styledxmlparser .css .media .MediaType ;
60
- import com .itextpdf .styledxmlparser .node .IDocumentNode ;
61
- import com .itextpdf .styledxmlparser .node .impl .jsoup .JsoupHtmlParser ;
62
- import com .itextpdf .test .ExtendedITextTest ;
63
47
import com .itextpdf .test .annotations .LogMessage ;
64
48
import com .itextpdf .test .annotations .LogMessages ;
65
49
import com .itextpdf .test .annotations .type .IntegrationTest ;
66
50
67
- import java .io .FileInputStream ;
68
- import org .junit .Assert ;
51
+ import java .io .IOException ;
69
52
import org .junit .BeforeClass ;
70
53
import org .junit .Test ;
71
54
import org .junit .experimental .categories .Category ;
72
55
73
- import java .io .File ;
74
- import java .io .IOException ;
75
-
76
56
@ Category (IntegrationTest .class )
77
- public class Html2PdfTest extends ExtendedITextTest {
57
+ public class Html2PdfTest extends ExtendedHtmlConversionITextTest {
78
58
79
- public static final String sourceFolder = "./src/test/resources/com/itextpdf/html2pdf/Html2PdfTest/" ;
80
- public static final String destinationFolder = "./target/test/com/itextpdf/html2pdf/Html2PdfTest/" ;
59
+ public static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/html2pdf/Html2PdfTest/" ;
60
+ public static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/html2pdf/Html2PdfTest/" ;
81
61
82
62
@ BeforeClass
83
63
public static void beforeClass () {
84
- createDestinationFolder ( destinationFolder );
64
+ createOrClearDestinationFolder ( DESTINATION_FOLDER );
85
65
}
86
66
87
67
@ Test
88
68
public void helloWorldParagraphTest () throws IOException , InterruptedException {
89
- convertAndCompare (sourceFolder + "hello_paragraph.html" , destinationFolder + "hello_paragraph.pdf" ,
90
- sourceFolder + "cmp_hello_paragraph.pdf" , destinationFolder , "diff01_" );
69
+ convertToPdfAndCompare ("hello_paragraph" , SOURCE_FOLDER , DESTINATION_FOLDER );
91
70
}
92
71
93
72
@ Test
94
- // TODO DEVSIX-1124
95
73
public void helloParagraphTableTest () throws IOException , InterruptedException {
96
- convertAndCompare (sourceFolder + "hello_paragraph_table.html" , destinationFolder + "hello_paragraph_table.pdf" ,
97
- sourceFolder + "cmp_hello_paragraph_table.pdf" , destinationFolder , "diff02_" );
74
+ convertToPdfAndCompare ("hello_paragraph_table" , SOURCE_FOLDER , DESTINATION_FOLDER );
98
75
}
99
76
100
77
@ Test
101
78
public void helloMalformedDocumentTest () throws IOException , InterruptedException {
102
- convertAndCompare (sourceFolder + "hello_malformed.html" , destinationFolder + "hello_malformed.pdf" ,
103
- sourceFolder + "cmp_hello_malformed.pdf" , destinationFolder , "diff03_" );
79
+ convertToPdfAndCompare ("hello_malformed" , SOURCE_FOLDER , DESTINATION_FOLDER );
104
80
}
105
81
106
82
@ Test
107
83
public void helloParagraphJunkSpacesDocumentTest () throws IOException , InterruptedException {
108
- convertAndCompare (sourceFolder + "hello_paragraph_junk_spaces.html" , destinationFolder + "hello_paragraph_junk_spaces.pdf" ,
109
- sourceFolder + "cmp_hello_paragraph_junk_spaces.pdf" , destinationFolder , "diff03_" );
84
+ convertToPdfAndCompare ("hello_paragraph_junk_spaces" , SOURCE_FOLDER , DESTINATION_FOLDER );
110
85
}
111
86
112
87
@ Test
113
- // TODO DEVSIX-1124
114
88
public void helloParagraphNestedInTableDocumentTest () throws IOException , InterruptedException {
115
- convertAndCompare (sourceFolder + "hello_paragraph_nested_in_table.html" , destinationFolder + "hello_paragraph_nested_in_table.pdf" ,
116
- sourceFolder + "cmp_hello_paragraph_nested_in_table.pdf" , destinationFolder , "diff03_" );
89
+ convertToPdfAndCompare ("hello_paragraph_nested_in_table" , SOURCE_FOLDER , DESTINATION_FOLDER );
117
90
}
118
91
119
92
@ Test
120
93
public void helloParagraphWithSpansDocumentTest () throws IOException , InterruptedException {
121
- convertAndCompare (sourceFolder + "hello_paragraph_with_span.html" , destinationFolder + "hello_paragraph_with_span.pdf" ,
122
- sourceFolder + "cmp_hello_paragraph_with_span.pdf" , destinationFolder , "diff03_" );
94
+ convertToPdfAndCompare ("hello_paragraph_with_span" , SOURCE_FOLDER , DESTINATION_FOLDER );
123
95
}
124
96
125
97
@ Test
126
98
public void helloDivDocumentTest () throws IOException , InterruptedException {
127
- convertAndCompare (sourceFolder + "hello_div.html" , destinationFolder + "hello_div.pdf" ,
128
- sourceFolder + "cmp_hello_div.pdf" , destinationFolder , "diff03_" );
99
+ convertToPdfAndCompare ("hello_div" , SOURCE_FOLDER , DESTINATION_FOLDER );
129
100
}
130
101
131
102
@ Test
132
103
public void aBlockInPTagTest () throws IOException , InterruptedException {
133
- convertAndCompare (sourceFolder + "aBlockInPTag.html" , destinationFolder + "aBlockInPTag.pdf" ,
134
- sourceFolder + "cmp_aBlockInPTag.pdf" , destinationFolder , "diff03_" );
104
+ convertToPdfAndCompare ("aBlockInPTag" , SOURCE_FOLDER , DESTINATION_FOLDER );
135
105
}
136
106
137
107
@ Test
138
108
public void base64svgTest () throws IOException , InterruptedException {
139
- HtmlConverter .convertToPdf (new File (sourceFolder + "objectTag_base64svg.html" ), new File (destinationFolder + "objectTag_base64svg.pdf" ));
140
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + "objectTag_base64svg.pdf" , sourceFolder + "cmp_objectTag_base64svg.pdf" , destinationFolder , "diff01_" ));
109
+ convertToPdfAndCompare ("objectTag_base64svg" , SOURCE_FOLDER , DESTINATION_FOLDER );
141
110
}
142
111
143
112
@ Test
144
- @ LogMessages (messages = {@ LogMessage (messageTemplate = StyledXmlParserLogMessageConstant .UNABLE_TO_RETRIEVE_STREAM_WITH_GIVEN_BASE_URI , count = 1 ),
113
+ @ LogMessages (messages = {
114
+ @ LogMessage (messageTemplate =
115
+ StyledXmlParserLogMessageConstant .UNABLE_TO_RETRIEVE_STREAM_WITH_GIVEN_BASE_URI , count = 1 ),
145
116
@ LogMessage (messageTemplate = Html2PdfLogMessageConstant .WORKER_UNABLE_TO_PROCESS_OTHER_WORKER , count = 1 )})
146
117
public void htmlObjectIncorrectBase64Test () throws IOException , InterruptedException {
147
- HtmlConverter .convertToPdf (new File (sourceFolder + "objectTag_incorrectBase64svg.html" ), new File (destinationFolder + "objectTag_incorrectBase64svg.pdf" ));
148
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + "objectTag_incorrectBase64svg.pdf" , sourceFolder + "cmp_objectTag_incorrectBase64svg.pdf" , destinationFolder , "diff01_" ));
149
-
118
+ convertToPdfAndCompare ("objectTag_incorrectBase64svg" , SOURCE_FOLDER , DESTINATION_FOLDER );
150
119
}
151
120
152
121
@ Test
153
- @ LogMessages (messages = {@ LogMessage (messageTemplate = Html2PdfLogMessageConstant .WORKER_UNABLE_TO_PROCESS_IT_S_TEXT_CONTENT , count = 1 ),
122
+ //TODO: update after DEVSIX-1346
123
+ @ LogMessages (messages = {
124
+ @ LogMessage (messageTemplate = Html2PdfLogMessageConstant .WORKER_UNABLE_TO_PROCESS_IT_S_TEXT_CONTENT ,
125
+ count = 1 ),
154
126
@ LogMessage (messageTemplate = Html2PdfLogMessageConstant .WORKER_UNABLE_TO_PROCESS_OTHER_WORKER , count = 2 ),
155
127
})
156
128
public void htmlObjectAltTextTest () throws IOException , InterruptedException {
157
- //update after DEVSIX-1346
158
- HtmlConverter .convertToPdf (new File (sourceFolder + "objectTag_altText.html" ), new File (destinationFolder + "objectTag_altText.pdf" ));
159
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + "objectTag_altText.pdf" , sourceFolder + "cmp_objectTag_altText.pdf" , destinationFolder , "diff01_" ));
160
-
129
+ convertToPdfAndCompare ("objectTag_altText" , SOURCE_FOLDER , DESTINATION_FOLDER );
161
130
}
162
131
163
132
@ Test
164
- @ LogMessages (messages = {@ LogMessage (messageTemplate = Html2PdfLogMessageConstant .WORKER_UNABLE_TO_PROCESS_OTHER_WORKER , count = 1 ),})
133
+ @ LogMessages (messages = {
134
+ @ LogMessage (messageTemplate = Html2PdfLogMessageConstant .WORKER_UNABLE_TO_PROCESS_OTHER_WORKER ,
135
+ count = 1 ),})
165
136
public void htmlObjectNestedObjectTest () throws IOException , InterruptedException {
166
- HtmlConverter .convertToPdf (new File (sourceFolder + "objectTag_nestedTag.html" ), new File (destinationFolder + "objectTag_nestedTag.pdf" ));
167
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + "objectTag_nestedTag.pdf" , sourceFolder + "cmp_objectTag_nestedTag.pdf" , destinationFolder , "diff01_" ));
137
+ convertToPdfAndCompare ("objectTag_nestedTag" , SOURCE_FOLDER , DESTINATION_FOLDER );
168
138
}
169
139
170
140
@ Test
171
- @ LogMessages (ignore = true , messages = {
172
- @ LogMessage (messageTemplate = StyledXmlParserLogMessageConstant .RULE_IS_NOT_SUPPORTED ),
173
- @ LogMessage (messageTemplate = Html2PdfLogMessageConstant .CSS_PROPERTY_IN_PERCENTS_NOT_SUPPORTED ),
174
- @ LogMessage (messageTemplate = Html2PdfLogMessageConstant .PADDING_VALUE_IN_PERCENT_NOT_SUPPORTED ),
175
- @ LogMessage (messageTemplate = Html2PdfLogMessageConstant .MARGIN_VALUE_IN_PERCENT_NOT_SUPPORTED ),
176
- @ LogMessage (messageTemplate = Html2PdfLogMessageConstant .ERROR_PARSING_CSS_SELECTOR ),
177
- @ LogMessage (messageTemplate = IoLogMessageConstant .WIDOWS_CONSTRAINT_VIOLATED ),
178
- })
179
- public void batchConversionTest () throws IOException , InterruptedException {
180
- ConverterProperties properties = new ConverterProperties ().setBaseUri (sourceFolder )
181
- .setMediaDeviceDescription (new MediaDeviceDescription (MediaType .PRINT ));
182
- FontProvider fontProvider = new DefaultFontProvider (true , false , false );
183
- fontProvider .addDirectory (sourceFolder + "fonts/" );
184
- properties .setFontProvider (fontProvider );
185
- IHtmlProcessor processor = new DefaultHtmlProcessor (properties );
186
-
187
- IXmlParser parser = new JsoupHtmlParser ();
188
- String outPdfPath = destinationFolder + "smashing1.pdf" ;
189
- PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outPdfPath ));
190
- IDocumentNode doc = parser .parse (new FileInputStream (sourceFolder + "smashing01.html" ),
191
- properties .getCharset ());
192
- Document document = processor .processDocument (doc , pdfDocument );
193
- document .close ();
194
-
195
- Assert .assertNull (new CompareTool ().compareByContent (outPdfPath ,
196
- sourceFolder + "cmp_smashing1.pdf" , destinationFolder , "diff01_" ));
197
- }
198
-
199
- @ Test
200
- public void htmlImgBase64SVGTest () throws IOException , InterruptedException {
201
- HtmlConverter .convertToPdf (new File (sourceFolder + "imgTag_base64svg.html" ), new File (destinationFolder + "imgTag_base64svg.pdf" ));
202
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + "imgTag_base64svg.pdf" , sourceFolder + "cmp_imgTag_base64svg.pdf" , destinationFolder , "diff01_" ));
203
- }
204
-
205
- private void convertAndCompare (String srcFilename , String outFilename , String cmpFilename , String outFolder , String diff ) throws IOException , InterruptedException {
206
- HtmlConverter .convertToPdf (new File (srcFilename ), new File (outFilename ));
207
- System .out .println ("html: " + UrlUtil .getNormalizedFileUriString (srcFilename ) + "\n " );
208
- Assert .assertNull (new CompareTool ().compareByContent (outFilename , cmpFilename , outFolder , diff ));
141
+ public void htmlImgBase64SVGTest () throws IOException , InterruptedException {
142
+ convertToPdfAndCompare ("imgTag_base64svg" , SOURCE_FOLDER , DESTINATION_FOLDER );
209
143
}
210
144
}
0 commit comments