Skip to content

Commit 2d2556e

Browse files
committed
[RELEASE] iText pdfHtml 5.0.3
2 parents f96f0f1 + 0943c49 commit 2d2556e

File tree

3,444 files changed

+6032
-3247
lines changed

Some content is hidden

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

3,444 files changed

+6032
-3247
lines changed

pom.xml

+2-3
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>8.0.2</version>
8+
<version>8.0.3</version>
99
<relativePath />
1010
</parent>
1111

1212
<artifactId>html2pdf</artifactId>
13-
<version>5.0.2</version>
13+
<version>5.0.3</version>
1414

1515
<name>pdfHTML</name>
1616
<description>pdfHTML is an iText add-on that lets you to parse (X)HTML snippets and the associated CSS and converts
@@ -70,7 +70,6 @@
7070
<groupId>com.itextpdf</groupId>
7171
<artifactId>pdfa</artifactId>
7272
<version>${itext.version}</version>
73-
<scope>test</scope>
7473
</dependency>
7574
<dependency>
7675
<groupId>com.itextpdf</groupId>

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

+67-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2023 Apryse Group NV
3+
Copyright (c) 1998-2024 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.
@@ -26,10 +26,14 @@ This file is part of the iText (R) project.
2626
import com.itextpdf.html2pdf.attach.ITagWorkerFactory;
2727
import com.itextpdf.html2pdf.attach.impl.OutlineHandler;
2828
import com.itextpdf.html2pdf.css.apply.ICssApplierFactory;
29+
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
30+
import com.itextpdf.kernel.pdf.PdfOutputIntent;
2931
import com.itextpdf.layout.font.FontProvider;
3032
import com.itextpdf.styledxmlparser.css.media.MediaDeviceDescription;
3133
import com.itextpdf.styledxmlparser.resolver.resource.IResourceRetriever;
3234

35+
import java.io.InputStream;
36+
3337
/**
3438
* Properties that will be used by the {@link com.itextpdf.html2pdf.HtmlConverter}.
3539
*/
@@ -105,6 +109,16 @@ public class ConverterProperties {
105109
*/
106110
private boolean continuousContainerEnabled;
107111

112+
/**
113+
* Output intent for final destination device.
114+
*/
115+
private PdfOutputIntent outputIntent;
116+
117+
/**
118+
* Conformance level for conversion to pdf/a.
119+
*/
120+
private PdfAConformanceLevel conformanceLevel;
121+
108122
/**
109123
* Instantiates a new {@link ConverterProperties} instance.
110124
*/
@@ -396,6 +410,58 @@ public ConverterProperties setCharset(String charset) {
396410
return this;
397411
}
398412

413+
/**
414+
* Sets pdf document output intent (final destination device) to reproduce the color in the PDF.
415+
* Required parameter, when converting to pdf/a one have to specify an explicit output intent.
416+
*
417+
* <p>
418+
* Note, output intent isn't applicable for HtmlConverter#convertToElements methods
419+
* (e.g. {@link HtmlConverter#convertToElements(InputStream, ConverterProperties)})
420+
*
421+
* @param outputIntent a {@link PdfOutputIntent} instance
422+
*
423+
* @return the {@link ConverterProperties} instance
424+
*/
425+
public ConverterProperties setDocumentOutputIntent(PdfOutputIntent outputIntent) {
426+
this.outputIntent = outputIntent;
427+
return this;
428+
}
429+
430+
/**
431+
* Sets the generation and strictness level of the PDF/A that must be followed.
432+
* Required parameter, when converting to pdf/a one have to specify an explicit pdf/a conformance level.
433+
*
434+
* @param conformanceLevel a {@link PdfAConformanceLevel} constant
435+
*
436+
* @return the {@link ConverterProperties} instance
437+
*/
438+
public ConverterProperties setPdfAConformanceLevel(PdfAConformanceLevel conformanceLevel) {
439+
this.conformanceLevel = conformanceLevel;
440+
return this;
441+
}
442+
443+
/**
444+
* Gets pdf document output intent (final destination device) to reproduce the color in the PDF.
445+
*
446+
* <p>
447+
* Note, output intent isn't applicable for HtmlConverter#convertToElements methods
448+
* (e.g. {@link HtmlConverter#convertToElements(InputStream, ConverterProperties)})
449+
*
450+
* @return pdf output intent
451+
*/
452+
public PdfOutputIntent getDocumentOutputIntent() {
453+
return outputIntent;
454+
}
455+
456+
/**
457+
* Gets the generation and strictness level of the PDF/A that must be followed.
458+
*
459+
* @return pdf/a conformance level
460+
*/
461+
public PdfAConformanceLevel getConformanceLevel() {
462+
return conformanceLevel;
463+
}
464+
399465
/**
400466
* Checks if immediateFlush is set.
401467
* <p>

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

+67-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2023 Apryse Group NV
3+
Copyright (c) 1998-2024 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.
@@ -22,17 +22,22 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.html2pdf;
2424

25+
import com.itextpdf.commons.actions.contexts.IMetaInfo;
26+
import com.itextpdf.commons.utils.FileUtil;
2527
import com.itextpdf.html2pdf.attach.Attacher;
2628
import com.itextpdf.html2pdf.exceptions.Html2PdfException;
27-
import com.itextpdf.commons.utils.FileUtil;
28-
import com.itextpdf.commons.actions.contexts.IMetaInfo;
29+
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
2930
import com.itextpdf.kernel.pdf.DocumentProperties;
31+
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
3032
import com.itextpdf.kernel.pdf.PdfDocument;
33+
import com.itextpdf.kernel.pdf.PdfVersion;
3134
import com.itextpdf.kernel.pdf.PdfWriter;
35+
import com.itextpdf.kernel.pdf.WriterProperties;
3236
import com.itextpdf.layout.Document;
3337
import com.itextpdf.layout.element.IElement;
3438
import com.itextpdf.layout.properties.Property;
3539
import com.itextpdf.layout.renderer.MetaInfoContainer;
40+
import com.itextpdf.pdfa.PdfADocument;
3641
import com.itextpdf.styledxmlparser.IXmlParser;
3742
import com.itextpdf.styledxmlparser.node.IDocumentNode;
3843
import com.itextpdf.styledxmlparser.node.impl.jsoup.JsoupHtmlParser;
@@ -43,6 +48,8 @@ This file is part of the iText (R) project.
4348
import java.io.IOException;
4449
import java.io.InputStream;
4550
import java.io.OutputStream;
51+
import java.util.ArrayList;
52+
import java.util.Arrays;
4653
import java.util.List;
4754

4855
/**
@@ -55,6 +62,8 @@ This file is part of the iText (R) project.
5562
*/
5663
public class HtmlConverter {
5764

65+
private static final List<PdfAConformanceLevel> pdf2ConformanceLevels = new ArrayList<>(Arrays. asList(PdfAConformanceLevel.PDF_A_4, PdfAConformanceLevel.PDF_A_4E, PdfAConformanceLevel.PDF_A_4F));
66+
5867
/**
5968
* Instantiates a new HtmlConverter instance.
6069
*/
@@ -81,6 +90,10 @@ public static void convertToPdf(String html, OutputStream pdfStream) {
8190
* @param converterProperties a {@link ConverterProperties} instance
8291
*/
8392
public static void convertToPdf(String html, OutputStream pdfStream, ConverterProperties converterProperties) {
93+
if (converterProperties != null && pdf2ConformanceLevels.contains(converterProperties.getConformanceLevel())) {
94+
convertToPdf(html, new PdfWriter(pdfStream, new WriterProperties().setPdfVersion(PdfVersion.PDF_2_0)), converterProperties);
95+
return;
96+
}
8497
convertToPdf(html, new PdfWriter(pdfStream), converterProperties);
8598
}
8699

@@ -104,8 +117,19 @@ public static void convertToPdf(String html, PdfWriter pdfWriter) {
104117
* @param converterProperties a {@link ConverterProperties} instance
105118
*/
106119
public static void convertToPdf(String html, PdfWriter pdfWriter, ConverterProperties converterProperties) {
107-
convertToPdf(html, new PdfDocument(pdfWriter, new DocumentProperties()
108-
.setEventCountingMetaInfo(resolveMetaInfo(converterProperties))), converterProperties);
120+
if (converterProperties == null || converterProperties.getConformanceLevel() == null) {
121+
convertToPdf(html, new PdfDocument(pdfWriter, new DocumentProperties()
122+
.setEventCountingMetaInfo(resolveMetaInfo(converterProperties))), converterProperties);
123+
return;
124+
}
125+
PdfDocument document = new PdfADocument(pdfWriter, converterProperties.getConformanceLevel(),
126+
converterProperties.getDocumentOutputIntent(), new DocumentProperties()
127+
.setEventCountingMetaInfo(resolveMetaInfo(converterProperties)));
128+
converterProperties = setDefaultFontProviderForPdfA(document, converterProperties);
129+
if ("A".equals(converterProperties.getConformanceLevel().getConformance())) {
130+
document.setTagged();
131+
}
132+
convertToPdf(html, document, converterProperties);
109133
}
110134

111135
/**
@@ -178,6 +202,10 @@ public static void convertToPdf(InputStream htmlStream, OutputStream pdfStream)
178202
* @throws IOException Signals that an I/O exception has occurred.
179203
*/
180204
public static void convertToPdf(InputStream htmlStream, OutputStream pdfStream, ConverterProperties converterProperties) throws IOException {
205+
if (converterProperties != null && pdf2ConformanceLevels.contains(converterProperties.getConformanceLevel())) {
206+
convertToPdf(htmlStream, new PdfWriter(pdfStream, new WriterProperties().setPdfVersion(PdfVersion.PDF_2_0)), converterProperties);
207+
return;
208+
}
181209
convertToPdf(htmlStream, new PdfWriter(pdfStream), converterProperties);
182210
}
183211

@@ -217,8 +245,19 @@ public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter) thr
217245
* @throws IOException Signals that an I/O exception has occurred.
218246
*/
219247
public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter, ConverterProperties converterProperties) throws IOException {
220-
convertToPdf(htmlStream, new PdfDocument(pdfWriter, new DocumentProperties().setEventCountingMetaInfo(
221-
resolveMetaInfo(converterProperties))), converterProperties);
248+
if (converterProperties == null || converterProperties.getConformanceLevel() == null) {
249+
convertToPdf(htmlStream, new PdfDocument(pdfWriter, new DocumentProperties().setEventCountingMetaInfo(
250+
resolveMetaInfo(converterProperties))), converterProperties);
251+
return;
252+
}
253+
PdfDocument document = new PdfADocument(pdfWriter, converterProperties.getConformanceLevel(),
254+
converterProperties.getDocumentOutputIntent(), new DocumentProperties()
255+
.setEventCountingMetaInfo(resolveMetaInfo(converterProperties)));
256+
converterProperties = setDefaultFontProviderForPdfA(document, converterProperties);
257+
if ("A".equals(converterProperties.getConformanceLevel().getConformance())) {
258+
document.setTagged();
259+
}
260+
convertToPdf(htmlStream, document, converterProperties);
222261
}
223262

224263
/**
@@ -231,6 +270,7 @@ public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter, Con
231270
* @throws IOException Signals that an I/O exception has occurred.
232271
*/
233272
public static void convertToPdf(InputStream htmlStream, PdfDocument pdfDocument, ConverterProperties converterProperties) throws IOException {
273+
converterProperties = setDefaultFontProviderForPdfA(pdfDocument, converterProperties);
234274
final Document document = convertToDocument(htmlStream, pdfDocument, converterProperties);
235275
IMetaInfo metaInfo = resolveMetaInfo(converterProperties);
236276
document.setProperty(Property.META_INFO, new MetaInfoContainer(metaInfo));
@@ -305,6 +345,7 @@ public static Document convertToDocument(String html, PdfDocument pdfDocument, C
305345
if (pdfDocument.getReader() != null) {
306346
throw new Html2PdfException(Html2PdfException.PDF_DOCUMENT_SHOULD_BE_IN_WRITING_MODE);
307347
}
348+
converterProperties = setDefaultFontProviderForPdfA(pdfDocument, converterProperties);
308349
IXmlParser parser = new JsoupHtmlParser();
309350
IDocumentNode doc = parser.parse(html);
310351
return Attacher.attach(doc, pdfDocument, converterProperties);
@@ -325,6 +366,7 @@ public static Document convertToDocument(InputStream htmlStream, PdfDocument pdf
325366
if (pdfDocument.getReader() != null) {
326367
throw new Html2PdfException(Html2PdfException.PDF_DOCUMENT_SHOULD_BE_IN_WRITING_MODE);
327368
}
369+
converterProperties = setDefaultFontProviderForPdfA(pdfDocument, converterProperties);
328370
IXmlParser parser = new JsoupHtmlParser();
329371
IDocumentNode doc = parser.parse(htmlStream, converterProperties != null ? converterProperties.getCharset() : null);
330372
return Attacher.attach(doc, pdfDocument, converterProperties);
@@ -363,6 +405,7 @@ public static List<IElement> convertToElements(InputStream htmlStream) throws IO
363405
* @return a list of iText building blocks
364406
*/
365407
public static List<IElement> convertToElements(String html, ConverterProperties converterProperties) {
408+
converterProperties = setDefaultFontProviderForPdfA(null, converterProperties);
366409
IXmlParser parser = new JsoupHtmlParser();
367410
IDocumentNode doc = parser.parse(html);
368411
return Attacher.attach(doc, converterProperties);
@@ -379,6 +422,7 @@ public static List<IElement> convertToElements(String html, ConverterProperties
379422
* @throws IOException Signals that an I/O exception has occurred.
380423
*/
381424
public static List<IElement> convertToElements(InputStream htmlStream, ConverterProperties converterProperties) throws IOException {
425+
converterProperties = setDefaultFontProviderForPdfA(null, converterProperties);
382426
IXmlParser parser = new JsoupHtmlParser();
383427
IDocumentNode doc = parser.parse(htmlStream, converterProperties != null ? converterProperties.getCharset() : null);
384428
return Attacher.attach(doc, converterProperties);
@@ -394,6 +438,22 @@ private static IMetaInfo resolveMetaInfo(ConverterProperties converterProperties
394438
: converterProperties.getEventMetaInfo();
395439
}
396440

441+
private static ConverterProperties setDefaultFontProviderForPdfA(PdfDocument document, ConverterProperties properties) {
442+
if (document instanceof PdfADocument) {
443+
if (properties == null) {
444+
properties = new ConverterProperties();
445+
}
446+
if (properties.getFontProvider() == null) {
447+
properties.setFontProvider(new DefaultFontProvider(false, true, false));
448+
}
449+
} else if (document == null && properties != null && properties.getConformanceLevel() != null) {
450+
if (properties.getFontProvider() == null) {
451+
properties.setFontProvider(new DefaultFontProvider(false, true, false));
452+
}
453+
}
454+
return properties;
455+
}
456+
397457
private static class HtmlMetaInfo implements IMetaInfo {
398458
}
399459
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2023 Apryse Group NV
3+
Copyright (c) 1998-2024 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/html2pdf/actions/data/PdfHtmlProductData.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2023 Apryse Group NV
3+
Copyright (c) 1998-2024 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.
@@ -30,9 +30,9 @@ This file is part of the iText (R) project.
3030
*/
3131
public final class PdfHtmlProductData {
3232
private static final String PDF_HTML_PUBLIC_PRODUCT_NAME = "pdfHTML";
33-
private static final String PDF_HTML_VERSION = "5.0.2";
33+
private static final String PDF_HTML_VERSION = "5.0.3";
3434
private static final int PDF_HTML_COPYRIGHT_SINCE = 2000;
35-
private static final int PDF_HTML_COPYRIGHT_TO = 2023;
35+
private static final int PDF_HTML_COPYRIGHT_TO = 2024;
3636

3737
private static final ProductData PDF_HTML_PRODUCT_DATA = new ProductData(PDF_HTML_PUBLIC_PRODUCT_NAME,
3838
ProductNameConstant.PDF_HTML, PDF_HTML_VERSION, PDF_HTML_COPYRIGHT_SINCE, PDF_HTML_COPYRIGHT_TO);

src/main/java/com/itextpdf/html2pdf/actions/events/PdfHtmlProductEvent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2023 Apryse Group NV
3+
Copyright (c) 1998-2024 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/html2pdf/attach/Attacher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2023 Apryse Group NV
3+
Copyright (c) 1998-2024 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/html2pdf/attach/IHtmlProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2023 Apryse Group NV
3+
Copyright (c) 1998-2024 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/html2pdf/attach/ITagWorker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2023 Apryse Group NV
3+
Copyright (c) 1998-2024 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/html2pdf/attach/ITagWorkerFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2023 Apryse Group NV
3+
Copyright (c) 1998-2024 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

0 commit comments

Comments
 (0)