@@ -42,7 +42,10 @@ This file is part of the iText (R) project.
4242 */
4343package com .itextpdf .html2pdf .element ;
4444
45+ import com .itextpdf .html2pdf .ConverterProperties ;
4546import com .itextpdf .html2pdf .HtmlConverter ;
47+ import com .itextpdf .kernel .pdf .PdfDocument ;
48+ import com .itextpdf .kernel .pdf .PdfWriter ;
4649import com .itextpdf .kernel .utils .CompareTool ;
4750import com .itextpdf .styledxmlparser .LogMessageConstant ;
4851import com .itextpdf .svg .exceptions .SvgLogMessageConstant ;
@@ -56,7 +59,6 @@ This file is part of the iText (R) project.
5659import org .junit .Test ;
5760import org .junit .experimental .categories .Category ;
5861import org .junit .rules .ExpectedException ;
59-
6062import java .io .File ;
6163import java .io .IOException ;
6264
@@ -66,6 +68,7 @@ public class SvgTest extends ExtendedITextTest {
6668 public static final String sourceFolder = "./src/test/resources/com/itextpdf/html2pdf/element/SvgTest/" ;
6769 public static final String destinationFolder = "./target/test/com/itextpdf/html2pdf/element/SvgTest/" ;
6870
71+
6972 @ Rule
7073 public ExpectedException junitExpectedException = ExpectedException .none ();
7174
@@ -103,6 +106,159 @@ public void inlineSvgExternalFontUrlTest() throws IOException, InterruptedExcept
103106 Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + name + ".pdf" , sourceFolder + "cmp_" + name + ".pdf" , destinationFolder , "diff_" + name + "_" ));
104107 }
105108
109+ @ Test
110+ @ LogMessages (messages = {
111+ @ LogMessage (messageTemplate = com .itextpdf .io .LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA ),
112+ })
113+ public void convert_inline_Svg_path_in_HTML () throws IOException , InterruptedException {
114+ String name = "HTML_with_inline_svg_path" ;
115+ HtmlConverter .convertToPdf (new File (sourceFolder + name + ".html" ), new File (destinationFolder + name + ".pdf" ));
116+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + name + ".pdf" , sourceFolder + "cmp_" + name + ".pdf" , destinationFolder , "diff_" + name + "_" ));
117+ }
118+
119+ @ Test
120+ @ LogMessages (messages = {
121+ @ LogMessage (messageTemplate = com .itextpdf .io .LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA ),
122+ })
123+ // TODO: Update cmp_ file when DEVSIX-2719 resolved
124+ public void convert_inline_Svg_polygon_in_HTML () throws IOException , InterruptedException {
125+ String name = "HTML_with_inline_svg_polygon" ;
126+ HtmlConverter .convertToPdf (new File (sourceFolder + name + ".html" ), new File (destinationFolder + name + ".pdf" ));
127+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + name + ".pdf" , sourceFolder + "cmp_" + name + ".pdf" , destinationFolder , "diff_" + name + "_" ));
128+ }
129+
130+ @ Test
131+ @ LogMessages (messages = {
132+ @ LogMessage (messageTemplate = com .itextpdf .io .LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA ),
133+ })
134+ public void convert_namespace_Svg_in_HTML () throws IOException , InterruptedException {
135+ String name = "namespace_svg" ;
136+ HtmlConverter .convertToPdf (new File (sourceFolder + name + ".html" ), new File (destinationFolder + name + ".pdf" ));
137+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + name + ".pdf" , sourceFolder + "cmp_" + name + ".pdf" , destinationFolder , "diff_" + name + "_" ));
138+ }
139+
140+ @ Test
141+ public void convertInlineSvgCircle () throws IOException , InterruptedException {
142+ String html = "inline_svg_circle" ;
143+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (destinationFolder + html + ".pdf" ));
144+ pdfDoc .addNewPage ();
145+ String string_file = "<!DOCTYPE html>\n " +
146+ "<html>\n " +
147+ "<body>\n " +
148+ "\n " +
149+ "<svg width=\" 100\" height=\" 100\" >\n " +
150+ " <circle cx=\" 50\" cy=\" 50\" r=\" 40\" stroke=\" green\" stroke-width=\" 4\" fill=\" yellow\" />\n " +
151+ "</svg>\n " +
152+ "\n " +
153+ "</body>\n " +
154+
155+ "</html>" ;
156+ HtmlConverter .convertToPdf (string_file , pdfDoc , new ConverterProperties ());
157+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + html + ".pdf" , sourceFolder + "cmp_" + html + ".pdf" , destinationFolder ));
158+ }
159+
160+
161+ @ Test
162+ public void convertInlineSvgRectangle () throws IOException , InterruptedException {
163+ String html = "inline_svg_rectangle" ;
164+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (destinationFolder + html + ".pdf" ));
165+ pdfDoc .addNewPage ();
166+ String string_file = "<!DOCTYPE html>\n " +
167+ "<html>\n " +
168+ "<body>\n " +
169+ "\n " +
170+ "<svg width=\" 400\" height=\" 100\" >\n " +
171+ " <rect width=\" 400\" height=\" 100\" \n " +
172+ " style=\" fill:rgb(0,0,255);stroke-width:10;stroke:rgb(0,0,0)\" />\n " +
173+ "Sorry, your browser does not support inline SVG.\n " +
174+ "</svg>\n " +
175+ " \n " +
176+ "</body>\n " +
177+ "</html>\n " ;
178+
179+ HtmlConverter .convertToPdf (string_file , pdfDoc , new ConverterProperties ());
180+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + html + ".pdf" , sourceFolder + "cmp_" + html + ".pdf" , destinationFolder ));
181+ }
182+
183+ @ Test
184+ public void convertInlineSvgRoundedRectangle () throws IOException , InterruptedException {
185+ String html = "inline_svg_rounded_rect" ;
186+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (destinationFolder + html + ".pdf" ));
187+ pdfDoc .addNewPage ();
188+ String string_file = "<!DOCTYPE html>\n " +
189+ "<html>\n " +
190+ "<body>\n " +
191+ "\n " +
192+ "<svg width=\" 400\" height=\" 180\" >\n " +
193+ " <rect x=\" 50\" y=\" 20\" rx=\" 20\" ry=\" 20\" width=\" 150\" height=\" 150\" \n " +
194+ " style=\" fill:red;stroke:black;stroke-width:5;opacity:0.5\" />\n " +
195+ "Sorry, your browser does not support inline SVG.\n " +
196+ "</svg>\n " +
197+ "\n " +
198+ "</body>\n " +
199+ "</html>\n " ;
200+
201+ HtmlConverter .convertToPdf (string_file , pdfDoc , new ConverterProperties ());
202+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + html + ".pdf" , sourceFolder + "cmp_" + html + ".pdf" , destinationFolder ));
203+ }
204+
205+ @ Test
206+ // TODO: Update cmp_ file when DEVSIX-2719 resolved
207+ public void convertInlineSvgStar () throws IOException , InterruptedException {
208+ String html = "inline_svg_star" ;
209+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (destinationFolder + html + ".pdf" ));
210+ pdfDoc .addNewPage ();
211+ String string_file = "<!DOCTYPE html>\n " +
212+ "<html>\n " +
213+ "<body>\n " +
214+ "\n " +
215+ "<svg width=\" 300\" height=\" 200\" >\n " +
216+ " <polygon points=\" 100,10 40,198 190,78 10,78 160,198\" \n " +
217+ " style=\" fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;\" />\n " +
218+ "Sorry, your browser does not support inline SVG.\n " +
219+ "</svg>\n " +
220+ " \n " +
221+ "</body>\n " +
222+ "</html>\n " ;
223+
224+ HtmlConverter .convertToPdf (string_file , pdfDoc , new ConverterProperties ());
225+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + html + ".pdf" , sourceFolder + "cmp_" + html + ".pdf" , destinationFolder ));
226+ }
227+
228+ @ Test
229+ @ LogMessages (messages = {
230+ @ LogMessage (messageTemplate = SvgLogMessageConstant .UNMAPPEDTAG ),
231+ })
232+ public void convertInlineSvgLogo () throws IOException , InterruptedException {
233+ String html = "inline_svg_logo" ;
234+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (destinationFolder + html + ".pdf" ));
235+ pdfDoc .addNewPage ();
236+ String string_file = "<!DOCTYPE html>\n " +
237+ " <html>\n " +
238+ " <body>\n " +
239+ "\n " +
240+ " <svg height=\" 130\" width=\" 500\" >\n " +
241+ " <defs>\n " +
242+ " <linearGradient id=\" grad1\" x1=\" 0%\" y1=\" 0%\" x2=\" 100%\" y2=\" 0%\" >\n " +
243+ " <stop offset=\" 0%\" \n " +
244+ " style=\" stop-color:rgb(255,255,0);stop-opacity:1\" />\n " +
245+ " <stop offset=\" 100%\" \n " +
246+ " style=\" stop-color:rgb(255,0,0);stop-opacity:1\" />\n " +
247+ " </linearGradient>\n " +
248+ " </defs>\n " +
249+ " <ellipse cx=\" 100\" cy=\" 70\" rx=\" 85\" ry=\" 55\" fill=\" url(#grad1)\" />\n " +
250+ " <text fill=\" #ffffff\" font-size=\" 45\" font-family=\" Verdana\" \n " +
251+ " x=\" 50\" y=\" 86\" >SVG</text>\n " +
252+ " Sorry, your browser does not support inline SVG.\n " +
253+ " </svg>\n " +
254+ "\n " +
255+ " </body>\n " +
256+ " </html>\n " ;
257+
258+ HtmlConverter .convertToPdf (string_file , pdfDoc , new ConverterProperties ());
259+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + html + ".pdf" , sourceFolder + "cmp_" + html + ".pdf" , destinationFolder ));
260+ }
261+
106262 @ Test
107263 public void externalImageSuccessTest () throws IOException , InterruptedException {
108264 String name = "external_img" ;
@@ -124,6 +280,10 @@ public void externalImageNonExistentRefTest() throws IOException, InterruptedExc
124280 }
125281
126282 @ Test
283+ //TODO update after DEVSIX-3034
284+ @ LogMessages (messages = {
285+ @ LogMessage (messageTemplate = com .itextpdf .html2pdf .LogMessageConstant .WORKER_UNABLE_TO_PROCESS_OTHER_WORKER , count = 2 )
286+ })
127287 public void externalObjectSuccessTest () throws IOException , InterruptedException {
128288 String name = "external_object" ;
129289 HtmlConverter .convertToPdf (new File (sourceFolder + name + ".html" ), new File (destinationFolder + name + ".pdf" ));
@@ -138,6 +298,18 @@ public void externalObjectWithResourceTest() throws IOException, InterruptedExce
138298 Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + name + ".pdf" , sourceFolder + "cmp_" + name + ".pdf" , destinationFolder , "diff_" + name + "_" ));
139299 }
140300
301+ @ Test
302+ @ LogMessages (messages = {
303+ @ LogMessage (messageTemplate = com .itextpdf .io .LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA , count = 66 ),
304+ @ LogMessage (messageTemplate = SvgLogMessageConstant .UNMAPPEDTAG , count = 67 ),
305+ })
306+ public void externalObjectWithGoogleCharts () throws IOException , InterruptedException {
307+ //TODO update after DEVSIX-2239
308+ String name = "inlineSvg_googleCharts" ;
309+ HtmlConverter .convertToPdf (new File (sourceFolder + name + ".html" ), new File (destinationFolder + name + ".pdf" ));
310+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + name + ".pdf" , sourceFolder + "cmp_" + name + ".pdf" , destinationFolder , "diff_" + name + "_" ));
311+ }
312+
141313 @ Test
142314 @ LogMessages (messages = {
143315 @ LogMessage (messageTemplate = LogMessageConstant .UNABLE_TO_RETRIEVE_STREAM_WITH_GIVEN_BASE_URI ),
@@ -149,6 +321,22 @@ public void externalObjectNonExistentRefTest() throws IOException, InterruptedEx
149321 Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + name + ".pdf" , sourceFolder + "cmp_" + name + ".pdf" , destinationFolder , "diff_" + name + "_" ));
150322 }
151323
324+ @ Test
325+ //TODO: Update cmp_ file when DEVSIX-2731 resolved
326+ public void htmlWithSvgBackground () throws IOException , InterruptedException {
327+ String name = "HTML_with_svg_background" ;
328+ HtmlConverter .convertToPdf (new File (sourceFolder + name + ".html" ), new File (destinationFolder + name + ".pdf" ));
329+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + name + ".pdf" , sourceFolder + "cmp_" + name + ".pdf" , destinationFolder , "diff_" + name + "_" ));
330+ }
331+
332+ @ Test
333+ //TODO: Update cmp_ file when DEVSIX-2731 resolved
334+ public void htmlWithSvgBackgroundNoViewbox () throws IOException , InterruptedException {
335+ String name = "Html_with_svg_background_no_viewbox" ;
336+ HtmlConverter .convertToPdf (new File (sourceFolder + name + ".html" ), new File (destinationFolder + name + ".pdf" ));
337+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + name + ".pdf" , sourceFolder + "cmp_" + name + ".pdf" , destinationFolder , "diff_" + name + "_" ));
338+ }
339+
152340 @ Test
153341 @ LogMessages (messages = {
154342 @ LogMessage (messageTemplate = SvgLogMessageConstant .MISSING_WIDTH ),
0 commit comments