@@ -42,6 +42,7 @@ 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 .impl .OutlineHandler ;
45
46
import com .itextpdf .layout .element .IElement ;
46
47
import com .itextpdf .layout .element .Paragraph ;
47
48
import com .itextpdf .layout .element .Table ;
@@ -152,4 +153,24 @@ public void htmlToElementsTest08() throws IOException {
152
153
String html = "<html><p>Hello world!</p><meta name=\" author\" content=\" Bruno\" ><table><tr><td>123</td><td><456></td></tr><tr><td>Long cell</td></tr></table><p>Hello world!</p></html>" ;
153
154
HtmlConverter .convertToElements (html );
154
155
}
156
+
157
+ @ Test
158
+ //Test OutlineHandler exception throwing
159
+ public void htmlToElementsTest09 () throws IOException {
160
+ /*
161
+ Outlines require a PdfDocument, and OutlineHandler is based around its availability
162
+ Any convert to elements workflow of course doesn't have a PdfDocument.
163
+ Instead of throwing an NPE when trying it, the OutlineHandler will check for the existence of a pdfDocument
164
+ If no PdfDocument is found, the handler will do nothing silently
165
+ */
166
+ String html = "<html><p>Hello world!</p><meta name=\" author\" content=\" Bruno\" ><table><tr><td>123</td><td><456></td></tr><tr><td>Long cell</td></tr></table><p>Hello world!</p></html>" ;
167
+ ConverterProperties props = new ConverterProperties ();
168
+ OutlineHandler outlineHandler = new OutlineHandler ();
169
+ outlineHandler .putTagPriorityMapping ("h1" , 1 );
170
+ outlineHandler .putTagPriorityMapping ("h3" ,2 );
171
+ outlineHandler .putTagPriorityMapping ("p" , 3 );
172
+ props .setOutlineHandler (outlineHandler );
173
+
174
+ HtmlConverter .convertToElements (html );
175
+ }
155
176
}
0 commit comments