Skip to content

Commit e5c7149

Browse files
committed
Merge branch 'release_branch_DEVSIX-5576' into master-rc
2 parents a7a478a + 7d64a02 commit e5c7149

File tree

642 files changed

+4236
-2681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

642 files changed

+4236
-2681
lines changed

pom.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<groupId>com.itextpdf</groupId>
77
<artifactId>root</artifactId>
8-
<version>7.1.16</version>
8+
<version>7.2.0</version>
99
<relativePath />
1010
</parent>
1111

1212
<artifactId>html2pdf</artifactId>
13-
<version>3.0.5</version>
13+
<version>4.0.0</version>
1414

1515
<name>pdfHTML</name>
1616
<description>pdfHTML is an iText 7 add-on that lets you to parse (X)HTML snippets and the associated CSS and converts
@@ -102,9 +102,6 @@
102102
<configuration>
103103
<sourceFileExcludes>
104104
<sourceFileExclude>com/itextpdf/html2pdf/attach/impl/layout/BodyHtmlStylesContainer.java</sourceFileExclude>
105-
106-
<!-- ProductInfo -->
107-
<sourceFileExclude>**/Html2PdfProductInfo.java</sourceFileExclude>
108105
</sourceFileExcludes>
109106
<groups>
110107
<group>

src/main/java/com/itextpdf/html2pdf/ConverterProperties.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ This file is part of the iText (R) project.
4646
import com.itextpdf.html2pdf.attach.ITagWorkerFactory;
4747
import com.itextpdf.html2pdf.attach.impl.OutlineHandler;
4848
import com.itextpdf.html2pdf.css.apply.ICssApplierFactory;
49-
import com.itextpdf.kernel.counter.event.IMetaInfo;
49+
import com.itextpdf.commons.actions.contexts.IMetaInfo;
5050
import com.itextpdf.layout.font.FontProvider;
5151
import com.itextpdf.styledxmlparser.css.media.MediaDeviceDescription;
5252
import com.itextpdf.styledxmlparser.resolver.resource.IResourceRetriever;
@@ -440,25 +440,23 @@ public ConverterProperties setImmediateFlush(boolean immediateFlush) {
440440
/**
441441
* Gets html meta info.
442442
* <p>
443-
* This meta info will be passed with to {@link com.itextpdf.kernel.counter.EventCounter}
444-
* with {@link com.itextpdf.html2pdf.events.PdfHtmlEvent} and can be used to determine event origin.
443+
* This meta info will be used to determine event origin.
445444
*
446445
* @return converter's {@link IMetaInfo}
447446
*/
448-
public IMetaInfo getEventCountingMetaInfo() {
449-
return metaInfo;
447+
IMetaInfo getEventMetaInfo() {
448+
return metaInfo == null ? HtmlConverter.createPdf2HtmlMetaInfo() : metaInfo;
450449
}
451450

452451
/**
453452
* Sets html meta info.
454453
* <p>
455-
* This meta info will be passed with to {@link com.itextpdf.kernel.counter.EventCounter}
456-
* with {@link com.itextpdf.html2pdf.events.PdfHtmlEvent} and can be used to determine event origin.
454+
* This meta info will be used to determine event origin.
457455
*
458456
* @param metaInfo meta info to set
459457
* @return the {@link ConverterProperties} instance
460458
*/
461-
public ConverterProperties setEventCountingMetaInfo(IMetaInfo metaInfo) {
459+
public ConverterProperties setEventMetaInfo(IMetaInfo metaInfo) {
462460
this.metaInfo = metaInfo;
463461
return this;
464462
}

src/main/java/com/itextpdf/html2pdf/Html2PdfProductInfo.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/main/java/com/itextpdf/html2pdf/HtmlConverter.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ This file is part of the iText (R) project.
4444
package com.itextpdf.html2pdf;
4545

4646
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;
5150
import com.itextpdf.kernel.pdf.DocumentProperties;
5251
import com.itextpdf.kernel.pdf.PdfDocument;
5352
import com.itextpdf.kernel.pdf.PdfWriter;
5453
import com.itextpdf.layout.Document;
5554
import com.itextpdf.layout.element.IElement;
55+
import com.itextpdf.layout.properties.Property;
56+
import com.itextpdf.layout.renderer.MetaInfoContainer;
5657
import com.itextpdf.styledxmlparser.IXmlParser;
5758
import com.itextpdf.styledxmlparser.node.IDocumentNode;
5859
import 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
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2021 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.html2pdf;
24+
25+
import com.itextpdf.html2pdf.attach.ProcessorContext;
26+
27+
/**
28+
* Class that creates ProcessorContext with IMetaInfo.
29+
*/
30+
public final class ProcessorContextCreator {
31+
32+
private ProcessorContextCreator() {
33+
// Should not be used
34+
}
35+
36+
/**
37+
* Crates ProcessorContext instances with IMetaInfo.
38+
*
39+
* @param converterProperties the {@link ConverterProperties} instance with IMetaInfo.
40+
*
41+
* @return a new {@link ProcessorContext} instance with IMetaInfo.
42+
*/
43+
public static ProcessorContext createProcessorContext(ConverterProperties converterProperties) {
44+
if (converterProperties == null) {
45+
converterProperties = new ConverterProperties();
46+
}
47+
ProcessorContext procContext = new ProcessorContext(converterProperties);
48+
procContext.setMetaInfo(converterProperties.getEventMetaInfo());
49+
return procContext;
50+
}
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2021 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.html2pdf.actions.data;
24+
25+
import com.itextpdf.commons.actions.data.ProductData;
26+
import com.itextpdf.commons.actions.ProductNameConstant;
27+
28+
/**
29+
* Stores an instance of {@link ProductData} related to iText pdfHTML module.
30+
*/
31+
public final class PdfHtmlProductData {
32+
private static final String PDF_HTML_PUBLIC_PRODUCT_NAME = "pdfHTML";
33+
private static final String PDF_HTML_VERSION = "4.0.0";
34+
private static final int PDF_HTML_COPYRIGHT_SINCE = 2000;
35+
private static final int PDF_HTML_COPYRIGHT_TO = 2021;
36+
37+
private static final ProductData PDF_HTML_PRODUCT_DATA = new ProductData(PDF_HTML_PUBLIC_PRODUCT_NAME,
38+
ProductNameConstant.PDF_HTML, PDF_HTML_VERSION, PDF_HTML_COPYRIGHT_SINCE, PDF_HTML_COPYRIGHT_TO);
39+
40+
private PdfHtmlProductData() {
41+
// Empty constructor.
42+
}
43+
44+
/**
45+
* Getter for an instance of {@link ProductData} related to iText pdfHTML module.
46+
*
47+
* @return iText pdfHTML product description
48+
*/
49+
public static ProductData getInstance() {
50+
return PDF_HTML_PRODUCT_DATA;
51+
}
52+
}

0 commit comments

Comments
 (0)