@@ -44,15 +44,16 @@ This file is part of the iText (R) project.
44
44
package com .itextpdf .html2pdf ;
45
45
46
46
import 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 ;
51
50
import com .itextpdf .kernel .pdf .DocumentProperties ;
52
51
import com .itextpdf .kernel .pdf .PdfDocument ;
53
52
import com .itextpdf .kernel .pdf .PdfWriter ;
54
53
import com .itextpdf .layout .Document ;
55
54
import com .itextpdf .layout .element .IElement ;
55
+ import com .itextpdf .layout .properties .Property ;
56
+ import com .itextpdf .layout .renderer .MetaInfoContainer ;
56
57
import com .itextpdf .styledxmlparser .IXmlParser ;
57
58
import com .itextpdf .styledxmlparser .node .IDocumentNode ;
58
59
import com .itextpdf .styledxmlparser .node .impl .jsoup .JsoupHtmlParser ;
@@ -124,7 +125,8 @@ public static void convertToPdf(String html, PdfWriter pdfWriter) {
124
125
* @param converterProperties a {@link ConverterProperties} instance
125
126
*/
126
127
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 );
128
130
}
129
131
130
132
/**
@@ -137,6 +139,7 @@ public static void convertToPdf(String html, PdfWriter pdfWriter, ConverterPrope
137
139
*/
138
140
public static void convertToPdf (String html , PdfDocument pdfDocument , ConverterProperties converterProperties ) {
139
141
final Document document = convertToDocument (html , pdfDocument , converterProperties );
142
+ document .setProperty (Property .META_INFO , new MetaInfoContainer (resolveMetaInfo (converterProperties )));
140
143
document .close ();
141
144
}
142
145
@@ -162,10 +165,10 @@ public static void convertToPdf(File htmlFile, File pdfFile) throws IOException
162
165
*/
163
166
public static void convertToPdf (File htmlFile , File pdfFile , ConverterProperties converterProperties ) throws IOException {
164
167
if (converterProperties == null ) {
165
- String baseUri = FileUtil .getParentDirectory (htmlFile );
168
+ String baseUri = FileUtil .getParentDirectoryUri (htmlFile );
166
169
converterProperties = new ConverterProperties ().setBaseUri (baseUri );
167
170
} else if (converterProperties .getBaseUri () == null ) {
168
- String baseUri = FileUtil .getParentDirectory (htmlFile );
171
+ String baseUri = FileUtil .getParentDirectoryUri (htmlFile );
169
172
converterProperties = new ConverterProperties (converterProperties ).setBaseUri (baseUri );
170
173
}
171
174
try (FileInputStream fileInputStream = new FileInputStream (htmlFile .getAbsolutePath ());
@@ -220,7 +223,8 @@ public static void convertToPdf(InputStream htmlStream, PdfDocument pdfDocument)
220
223
* @throws IOException Signals that an I/O exception has occurred.
221
224
*/
222
225
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 ())));
224
228
}
225
229
226
230
/**
@@ -234,7 +238,8 @@ public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter) thr
234
238
* @throws IOException Signals that an I/O exception has occurred.
235
239
*/
236
240
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 );
238
243
}
239
244
240
245
/**
@@ -248,6 +253,8 @@ public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter, Con
248
253
*/
249
254
public static void convertToPdf (InputStream htmlStream , PdfDocument pdfDocument , ConverterProperties converterProperties ) throws IOException {
250
255
final Document document = convertToDocument (htmlStream , pdfDocument , converterProperties );
256
+ IMetaInfo metaInfo = resolveMetaInfo (converterProperties );
257
+ document .setProperty (Property .META_INFO , new MetaInfoContainer (metaInfo ));
251
258
document .close ();
252
259
}
253
260
@@ -316,9 +323,8 @@ public static Document convertToDocument(InputStream htmlStream, PdfWriter pdfWr
316
323
* @return a {@link Document} instance
317
324
*/
318
325
public static Document convertToDocument (String html , PdfDocument pdfDocument , ConverterProperties converterProperties ) {
319
- ReflectionUtils .scheduledLicenseCheck ();
320
326
if (pdfDocument .getReader () != null ) {
321
- throw new Html2PdfException (Html2PdfException .PdfDocumentShouldBeInWritingMode );
327
+ throw new Html2PdfException (Html2PdfException .PDF_DOCUMENT_SHOULD_BE_IN_WRITING_MODE );
322
328
}
323
329
IXmlParser parser = new JsoupHtmlParser ();
324
330
IDocumentNode doc = parser .parse (html );
@@ -337,9 +343,8 @@ public static Document convertToDocument(String html, PdfDocument pdfDocument, C
337
343
* @throws IOException Signals that an I/O exception has occurred.
338
344
*/
339
345
public static Document convertToDocument (InputStream htmlStream , PdfDocument pdfDocument , ConverterProperties converterProperties ) throws IOException {
340
- ReflectionUtils .scheduledLicenseCheck ();
341
346
if (pdfDocument .getReader () != null ) {
342
- throw new Html2PdfException (Html2PdfException .PdfDocumentShouldBeInWritingMode );
347
+ throw new Html2PdfException (Html2PdfException .PDF_DOCUMENT_SHOULD_BE_IN_WRITING_MODE );
343
348
}
344
349
IXmlParser parser = new JsoupHtmlParser ();
345
350
IDocumentNode doc = parser .parse (htmlStream , converterProperties != null ? converterProperties .getCharset () : null );
@@ -379,7 +384,6 @@ public static List<IElement> convertToElements(InputStream htmlStream) throws IO
379
384
* @return a list of iText building blocks
380
385
*/
381
386
public static List <IElement > convertToElements (String html , ConverterProperties converterProperties ) {
382
- ReflectionUtils .scheduledLicenseCheck ();
383
387
IXmlParser parser = new JsoupHtmlParser ();
384
388
IDocumentNode doc = parser .parse (html );
385
389
return Attacher .attach (doc , converterProperties );
@@ -396,14 +400,21 @@ public static List<IElement> convertToElements(String html, ConverterProperties
396
400
* @throws IOException Signals that an I/O exception has occurred.
397
401
*/
398
402
public static List <IElement > convertToElements (InputStream htmlStream , ConverterProperties converterProperties ) throws IOException {
399
- ReflectionUtils .scheduledLicenseCheck ();
400
403
IXmlParser parser = new JsoupHtmlParser ();
401
404
IDocumentNode doc = parser .parse (htmlStream , converterProperties != null ? converterProperties .getCharset () : null );
402
405
return Attacher .attach (doc , converterProperties );
403
406
}
404
407
405
- private static class HtmlMetaInfo implements IMetaInfo {
408
+ static IMetaInfo createPdf2HtmlMetaInfo () {
409
+ return new HtmlMetaInfo ();
410
+ }
406
411
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 {
408
419
}
409
420
}
0 commit comments