@@ -44,15 +44,16 @@ This file is part of the iText (R) project.
4444package com .itextpdf .html2pdf ;
4545
4646import com .itextpdf .html2pdf .attach .Attacher ;
47- import com .itextpdf .html2pdf .exception .Html2PdfException ;
48- import com .itextpdf .html2pdf .util .ReflectionUtils ;
49- import com .itextpdf .io .util .FileUtil ;
50- import com .itextpdf .kernel .counter .event .IMetaInfo ;
47+ import com .itextpdf .html2pdf .exceptions .Html2PdfException ;
48+ import com .itextpdf .commons .utils .FileUtil ;
49+ import com .itextpdf .commons .actions .contexts .IMetaInfo ;
5150import com .itextpdf .kernel .pdf .DocumentProperties ;
5251import com .itextpdf .kernel .pdf .PdfDocument ;
5352import com .itextpdf .kernel .pdf .PdfWriter ;
5453import com .itextpdf .layout .Document ;
5554import com .itextpdf .layout .element .IElement ;
55+ import com .itextpdf .layout .properties .Property ;
56+ import com .itextpdf .layout .renderer .MetaInfoContainer ;
5657import com .itextpdf .styledxmlparser .IXmlParser ;
5758import com .itextpdf .styledxmlparser .node .IDocumentNode ;
5859import com .itextpdf .styledxmlparser .node .impl .jsoup .JsoupHtmlParser ;
@@ -124,7 +125,8 @@ public static void convertToPdf(String html, PdfWriter pdfWriter) {
124125 * @param converterProperties a {@link ConverterProperties} instance
125126 */
126127 public static void convertToPdf (String html , PdfWriter pdfWriter , ConverterProperties converterProperties ) {
127- convertToPdf (html , new PdfDocument (pdfWriter , new DocumentProperties ().setEventCountingMetaInfo (new HtmlMetaInfo ())), converterProperties );
128+ convertToPdf (html , new PdfDocument (pdfWriter , new DocumentProperties ()
129+ .setEventCountingMetaInfo (resolveMetaInfo (converterProperties ))), converterProperties );
128130 }
129131
130132 /**
@@ -137,6 +139,7 @@ public static void convertToPdf(String html, PdfWriter pdfWriter, ConverterPrope
137139 */
138140 public static void convertToPdf (String html , PdfDocument pdfDocument , ConverterProperties converterProperties ) {
139141 final Document document = convertToDocument (html , pdfDocument , converterProperties );
142+ document .setProperty (Property .META_INFO , new MetaInfoContainer (resolveMetaInfo (converterProperties )));
140143 document .close ();
141144 }
142145
@@ -162,10 +165,10 @@ public static void convertToPdf(File htmlFile, File pdfFile) throws IOException
162165 */
163166 public static void convertToPdf (File htmlFile , File pdfFile , ConverterProperties converterProperties ) throws IOException {
164167 if (converterProperties == null ) {
165- String baseUri = FileUtil .getParentDirectory (htmlFile );
168+ String baseUri = FileUtil .getParentDirectoryUri (htmlFile );
166169 converterProperties = new ConverterProperties ().setBaseUri (baseUri );
167170 } else if (converterProperties .getBaseUri () == null ) {
168- String baseUri = FileUtil .getParentDirectory (htmlFile );
171+ String baseUri = FileUtil .getParentDirectoryUri (htmlFile );
169172 converterProperties = new ConverterProperties (converterProperties ).setBaseUri (baseUri );
170173 }
171174 try (FileInputStream fileInputStream = new FileInputStream (htmlFile .getAbsolutePath ());
@@ -220,7 +223,8 @@ public static void convertToPdf(InputStream htmlStream, PdfDocument pdfDocument)
220223 * @throws IOException Signals that an I/O exception has occurred.
221224 */
222225 public static void convertToPdf (InputStream htmlStream , PdfWriter pdfWriter ) throws IOException {
223- convertToPdf (htmlStream , new PdfDocument (pdfWriter , new DocumentProperties ().setEventCountingMetaInfo (new HtmlMetaInfo ())));
226+ convertToPdf (htmlStream , new PdfDocument (pdfWriter , new DocumentProperties ().setEventCountingMetaInfo (
227+ createPdf2HtmlMetaInfo ())));
224228 }
225229
226230 /**
@@ -234,7 +238,8 @@ public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter) thr
234238 * @throws IOException Signals that an I/O exception has occurred.
235239 */
236240 public static void convertToPdf (InputStream htmlStream , PdfWriter pdfWriter , ConverterProperties converterProperties ) throws IOException {
237- convertToPdf (htmlStream , new PdfDocument (pdfWriter , new DocumentProperties ().setEventCountingMetaInfo (new HtmlMetaInfo ())), converterProperties );
241+ convertToPdf (htmlStream , new PdfDocument (pdfWriter , new DocumentProperties ().setEventCountingMetaInfo (
242+ resolveMetaInfo (converterProperties ))), converterProperties );
238243 }
239244
240245 /**
@@ -248,6 +253,8 @@ public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter, Con
248253 */
249254 public static void convertToPdf (InputStream htmlStream , PdfDocument pdfDocument , ConverterProperties converterProperties ) throws IOException {
250255 final Document document = convertToDocument (htmlStream , pdfDocument , converterProperties );
256+ IMetaInfo metaInfo = resolveMetaInfo (converterProperties );
257+ document .setProperty (Property .META_INFO , new MetaInfoContainer (metaInfo ));
251258 document .close ();
252259 }
253260
@@ -316,9 +323,8 @@ public static Document convertToDocument(InputStream htmlStream, PdfWriter pdfWr
316323 * @return a {@link Document} instance
317324 */
318325 public static Document convertToDocument (String html , PdfDocument pdfDocument , ConverterProperties converterProperties ) {
319- ReflectionUtils .scheduledLicenseCheck ();
320326 if (pdfDocument .getReader () != null ) {
321- throw new Html2PdfException (Html2PdfException .PdfDocumentShouldBeInWritingMode );
327+ throw new Html2PdfException (Html2PdfException .PDF_DOCUMENT_SHOULD_BE_IN_WRITING_MODE );
322328 }
323329 IXmlParser parser = new JsoupHtmlParser ();
324330 IDocumentNode doc = parser .parse (html );
@@ -337,9 +343,8 @@ public static Document convertToDocument(String html, PdfDocument pdfDocument, C
337343 * @throws IOException Signals that an I/O exception has occurred.
338344 */
339345 public static Document convertToDocument (InputStream htmlStream , PdfDocument pdfDocument , ConverterProperties converterProperties ) throws IOException {
340- ReflectionUtils .scheduledLicenseCheck ();
341346 if (pdfDocument .getReader () != null ) {
342- throw new Html2PdfException (Html2PdfException .PdfDocumentShouldBeInWritingMode );
347+ throw new Html2PdfException (Html2PdfException .PDF_DOCUMENT_SHOULD_BE_IN_WRITING_MODE );
343348 }
344349 IXmlParser parser = new JsoupHtmlParser ();
345350 IDocumentNode doc = parser .parse (htmlStream , converterProperties != null ? converterProperties .getCharset () : null );
@@ -379,7 +384,6 @@ public static List<IElement> convertToElements(InputStream htmlStream) throws IO
379384 * @return a list of iText building blocks
380385 */
381386 public static List <IElement > convertToElements (String html , ConverterProperties converterProperties ) {
382- ReflectionUtils .scheduledLicenseCheck ();
383387 IXmlParser parser = new JsoupHtmlParser ();
384388 IDocumentNode doc = parser .parse (html );
385389 return Attacher .attach (doc , converterProperties );
@@ -396,14 +400,21 @@ public static List<IElement> convertToElements(String html, ConverterProperties
396400 * @throws IOException Signals that an I/O exception has occurred.
397401 */
398402 public static List <IElement > convertToElements (InputStream htmlStream , ConverterProperties converterProperties ) throws IOException {
399- ReflectionUtils .scheduledLicenseCheck ();
400403 IXmlParser parser = new JsoupHtmlParser ();
401404 IDocumentNode doc = parser .parse (htmlStream , converterProperties != null ? converterProperties .getCharset () : null );
402405 return Attacher .attach (doc , converterProperties );
403406 }
404407
405- private static class HtmlMetaInfo implements IMetaInfo {
408+ static IMetaInfo createPdf2HtmlMetaInfo () {
409+ return new HtmlMetaInfo ();
410+ }
406411
407- private static final long serialVersionUID = -295587336698550627L ;
412+ private static IMetaInfo resolveMetaInfo (ConverterProperties converterProperties ) {
413+ return converterProperties == null
414+ ? createPdf2HtmlMetaInfo ()
415+ : converterProperties .getEventMetaInfo ();
416+ }
417+
418+ private static class HtmlMetaInfo implements IMetaInfo {
408419 }
409420}
0 commit comments