@@ -42,6 +42,7 @@ This file is part of the iText (R) project.
4242 */
4343package com .itextpdf .html2pdf ;
4444
45+ import com .itextpdf .html2pdf .attach .impl .OutlineHandler ;
4546import com .itextpdf .layout .element .IElement ;
4647import com .itextpdf .layout .element .Paragraph ;
4748import com .itextpdf .layout .element .Table ;
@@ -153,4 +154,24 @@ public void htmlToElementsTest08() throws IOException {
153154 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>" ;
154155 HtmlConverter .convertToElements (html );
155156 }
157+
158+ @ Test
159+ //Test OutlineHandler exception throwing
160+ public void htmlToElementsTest09 () throws IOException {
161+ /*
162+ Outlines require a PdfDocument, and OutlineHandler is based around its availability
163+ Any convert to elements workflow of course doesn't have a PdfDocument.
164+ Instead of throwing an NPE when trying it, the OutlineHandler will check for the existence of a pdfDocument
165+ If no PdfDocument is found, the handler will do nothing silently
166+ */
167+ 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>" ;
168+ ConverterProperties props = new ConverterProperties ();
169+ OutlineHandler outlineHandler = new OutlineHandler ();
170+ outlineHandler .putTagPriorityMapping ("h1" , 1 );
171+ outlineHandler .putTagPriorityMapping ("h3" ,2 );
172+ outlineHandler .putTagPriorityMapping ("p" , 3 );
173+ props .setOutlineHandler (outlineHandler );
174+
175+ HtmlConverter .convertToElements (html );
176+ }
156177}
0 commit comments