Skip to content

Commit

Permalink
[RELEASE] iText pdfHtml 5.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
iText-CI committed Jan 30, 2024
2 parents f96f0f1 + 0943c49 commit 2d2556e
Show file tree
Hide file tree
Showing 3,444 changed files with 6,032 additions and 3,247 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>8.0.2</version>
<version>8.0.3</version>
<relativePath />
</parent>

<artifactId>html2pdf</artifactId>
<version>5.0.2</version>
<version>5.0.3</version>

<name>pdfHTML</name>
<description>pdfHTML is an iText add-on that lets you to parse (X)HTML snippets and the associated CSS and converts
Expand Down Expand Up @@ -70,7 +70,6 @@
<groupId>com.itextpdf</groupId>
<artifactId>pdfa</artifactId>
<version>${itext.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
Expand Down
68 changes: 67 additions & 1 deletion src/main/java/com/itextpdf/html2pdf/ConverterProperties.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand All @@ -26,10 +26,14 @@ This file is part of the iText (R) project.
import com.itextpdf.html2pdf.attach.ITagWorkerFactory;
import com.itextpdf.html2pdf.attach.impl.OutlineHandler;
import com.itextpdf.html2pdf.css.apply.ICssApplierFactory;
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
import com.itextpdf.kernel.pdf.PdfOutputIntent;
import com.itextpdf.layout.font.FontProvider;
import com.itextpdf.styledxmlparser.css.media.MediaDeviceDescription;
import com.itextpdf.styledxmlparser.resolver.resource.IResourceRetriever;

import java.io.InputStream;

/**
* Properties that will be used by the {@link com.itextpdf.html2pdf.HtmlConverter}.
*/
Expand Down Expand Up @@ -105,6 +109,16 @@ public class ConverterProperties {
*/
private boolean continuousContainerEnabled;

/**
* Output intent for final destination device.
*/
private PdfOutputIntent outputIntent;

/**
* Conformance level for conversion to pdf/a.
*/
private PdfAConformanceLevel conformanceLevel;

/**
* Instantiates a new {@link ConverterProperties} instance.
*/
Expand Down Expand Up @@ -396,6 +410,58 @@ public ConverterProperties setCharset(String charset) {
return this;
}

/**
* Sets pdf document output intent (final destination device) to reproduce the color in the PDF.
* Required parameter, when converting to pdf/a one have to specify an explicit output intent.
*
* <p>
* Note, output intent isn't applicable for HtmlConverter#convertToElements methods
* (e.g. {@link HtmlConverter#convertToElements(InputStream, ConverterProperties)})
*
* @param outputIntent a {@link PdfOutputIntent} instance
*
* @return the {@link ConverterProperties} instance
*/
public ConverterProperties setDocumentOutputIntent(PdfOutputIntent outputIntent) {
this.outputIntent = outputIntent;
return this;
}

/**
* Sets the generation and strictness level of the PDF/A that must be followed.
* Required parameter, when converting to pdf/a one have to specify an explicit pdf/a conformance level.
*
* @param conformanceLevel a {@link PdfAConformanceLevel} constant
*
* @return the {@link ConverterProperties} instance
*/
public ConverterProperties setPdfAConformanceLevel(PdfAConformanceLevel conformanceLevel) {
this.conformanceLevel = conformanceLevel;
return this;
}

/**
* Gets pdf document output intent (final destination device) to reproduce the color in the PDF.
*
* <p>
* Note, output intent isn't applicable for HtmlConverter#convertToElements methods
* (e.g. {@link HtmlConverter#convertToElements(InputStream, ConverterProperties)})
*
* @return pdf output intent
*/
public PdfOutputIntent getDocumentOutputIntent() {
return outputIntent;
}

/**
* Gets the generation and strictness level of the PDF/A that must be followed.
*
* @return pdf/a conformance level
*/
public PdfAConformanceLevel getConformanceLevel() {
return conformanceLevel;
}

/**
* Checks if immediateFlush is set.
* <p>
Expand Down
74 changes: 67 additions & 7 deletions src/main/java/com/itextpdf/html2pdf/HtmlConverter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand All @@ -22,17 +22,22 @@ This file is part of the iText (R) project.
*/
package com.itextpdf.html2pdf;

import com.itextpdf.commons.actions.contexts.IMetaInfo;
import com.itextpdf.commons.utils.FileUtil;
import com.itextpdf.html2pdf.attach.Attacher;
import com.itextpdf.html2pdf.exceptions.Html2PdfException;
import com.itextpdf.commons.utils.FileUtil;
import com.itextpdf.commons.actions.contexts.IMetaInfo;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.kernel.pdf.DocumentProperties;
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfVersion;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.WriterProperties;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.IElement;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.layout.renderer.MetaInfoContainer;
import com.itextpdf.pdfa.PdfADocument;
import com.itextpdf.styledxmlparser.IXmlParser;
import com.itextpdf.styledxmlparser.node.IDocumentNode;
import com.itextpdf.styledxmlparser.node.impl.jsoup.JsoupHtmlParser;
Expand All @@ -43,6 +48,8 @@ This file is part of the iText (R) project.
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

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

private static final List<PdfAConformanceLevel> pdf2ConformanceLevels = new ArrayList<>(Arrays. asList(PdfAConformanceLevel.PDF_A_4, PdfAConformanceLevel.PDF_A_4E, PdfAConformanceLevel.PDF_A_4F));

/**
* Instantiates a new HtmlConverter instance.
*/
Expand All @@ -81,6 +90,10 @@ public static void convertToPdf(String html, OutputStream pdfStream) {
* @param converterProperties a {@link ConverterProperties} instance
*/
public static void convertToPdf(String html, OutputStream pdfStream, ConverterProperties converterProperties) {
if (converterProperties != null && pdf2ConformanceLevels.contains(converterProperties.getConformanceLevel())) {
convertToPdf(html, new PdfWriter(pdfStream, new WriterProperties().setPdfVersion(PdfVersion.PDF_2_0)), converterProperties);
return;
}
convertToPdf(html, new PdfWriter(pdfStream), converterProperties);
}

Expand All @@ -104,8 +117,19 @@ public static void convertToPdf(String html, PdfWriter pdfWriter) {
* @param converterProperties a {@link ConverterProperties} instance
*/
public static void convertToPdf(String html, PdfWriter pdfWriter, ConverterProperties converterProperties) {
convertToPdf(html, new PdfDocument(pdfWriter, new DocumentProperties()
.setEventCountingMetaInfo(resolveMetaInfo(converterProperties))), converterProperties);
if (converterProperties == null || converterProperties.getConformanceLevel() == null) {
convertToPdf(html, new PdfDocument(pdfWriter, new DocumentProperties()
.setEventCountingMetaInfo(resolveMetaInfo(converterProperties))), converterProperties);
return;
}
PdfDocument document = new PdfADocument(pdfWriter, converterProperties.getConformanceLevel(),
converterProperties.getDocumentOutputIntent(), new DocumentProperties()
.setEventCountingMetaInfo(resolveMetaInfo(converterProperties)));
converterProperties = setDefaultFontProviderForPdfA(document, converterProperties);
if ("A".equals(converterProperties.getConformanceLevel().getConformance())) {
document.setTagged();
}
convertToPdf(html, document, converterProperties);
}

/**
Expand Down Expand Up @@ -178,6 +202,10 @@ public static void convertToPdf(InputStream htmlStream, OutputStream pdfStream)
* @throws IOException Signals that an I/O exception has occurred.
*/
public static void convertToPdf(InputStream htmlStream, OutputStream pdfStream, ConverterProperties converterProperties) throws IOException {
if (converterProperties != null && pdf2ConformanceLevels.contains(converterProperties.getConformanceLevel())) {
convertToPdf(htmlStream, new PdfWriter(pdfStream, new WriterProperties().setPdfVersion(PdfVersion.PDF_2_0)), converterProperties);
return;
}
convertToPdf(htmlStream, new PdfWriter(pdfStream), converterProperties);
}

Expand Down Expand Up @@ -217,8 +245,19 @@ public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter) thr
* @throws IOException Signals that an I/O exception has occurred.
*/
public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter, ConverterProperties converterProperties) throws IOException {
convertToPdf(htmlStream, new PdfDocument(pdfWriter, new DocumentProperties().setEventCountingMetaInfo(
resolveMetaInfo(converterProperties))), converterProperties);
if (converterProperties == null || converterProperties.getConformanceLevel() == null) {
convertToPdf(htmlStream, new PdfDocument(pdfWriter, new DocumentProperties().setEventCountingMetaInfo(
resolveMetaInfo(converterProperties))), converterProperties);
return;
}
PdfDocument document = new PdfADocument(pdfWriter, converterProperties.getConformanceLevel(),
converterProperties.getDocumentOutputIntent(), new DocumentProperties()
.setEventCountingMetaInfo(resolveMetaInfo(converterProperties)));
converterProperties = setDefaultFontProviderForPdfA(document, converterProperties);
if ("A".equals(converterProperties.getConformanceLevel().getConformance())) {
document.setTagged();
}
convertToPdf(htmlStream, document, converterProperties);
}

/**
Expand All @@ -231,6 +270,7 @@ public static void convertToPdf(InputStream htmlStream, PdfWriter pdfWriter, Con
* @throws IOException Signals that an I/O exception has occurred.
*/
public static void convertToPdf(InputStream htmlStream, PdfDocument pdfDocument, ConverterProperties converterProperties) throws IOException {
converterProperties = setDefaultFontProviderForPdfA(pdfDocument, converterProperties);
final Document document = convertToDocument(htmlStream, pdfDocument, converterProperties);
IMetaInfo metaInfo = resolveMetaInfo(converterProperties);
document.setProperty(Property.META_INFO, new MetaInfoContainer(metaInfo));
Expand Down Expand Up @@ -305,6 +345,7 @@ public static Document convertToDocument(String html, PdfDocument pdfDocument, C
if (pdfDocument.getReader() != null) {
throw new Html2PdfException(Html2PdfException.PDF_DOCUMENT_SHOULD_BE_IN_WRITING_MODE);
}
converterProperties = setDefaultFontProviderForPdfA(pdfDocument, converterProperties);
IXmlParser parser = new JsoupHtmlParser();
IDocumentNode doc = parser.parse(html);
return Attacher.attach(doc, pdfDocument, converterProperties);
Expand All @@ -325,6 +366,7 @@ public static Document convertToDocument(InputStream htmlStream, PdfDocument pdf
if (pdfDocument.getReader() != null) {
throw new Html2PdfException(Html2PdfException.PDF_DOCUMENT_SHOULD_BE_IN_WRITING_MODE);
}
converterProperties = setDefaultFontProviderForPdfA(pdfDocument, converterProperties);
IXmlParser parser = new JsoupHtmlParser();
IDocumentNode doc = parser.parse(htmlStream, converterProperties != null ? converterProperties.getCharset() : null);
return Attacher.attach(doc, pdfDocument, converterProperties);
Expand Down Expand Up @@ -363,6 +405,7 @@ public static List<IElement> convertToElements(InputStream htmlStream) throws IO
* @return a list of iText building blocks
*/
public static List<IElement> convertToElements(String html, ConverterProperties converterProperties) {
converterProperties = setDefaultFontProviderForPdfA(null, converterProperties);
IXmlParser parser = new JsoupHtmlParser();
IDocumentNode doc = parser.parse(html);
return Attacher.attach(doc, converterProperties);
Expand All @@ -379,6 +422,7 @@ public static List<IElement> convertToElements(String html, ConverterProperties
* @throws IOException Signals that an I/O exception has occurred.
*/
public static List<IElement> convertToElements(InputStream htmlStream, ConverterProperties converterProperties) throws IOException {
converterProperties = setDefaultFontProviderForPdfA(null, converterProperties);
IXmlParser parser = new JsoupHtmlParser();
IDocumentNode doc = parser.parse(htmlStream, converterProperties != null ? converterProperties.getCharset() : null);
return Attacher.attach(doc, converterProperties);
Expand All @@ -394,6 +438,22 @@ private static IMetaInfo resolveMetaInfo(ConverterProperties converterProperties
: converterProperties.getEventMetaInfo();
}

private static ConverterProperties setDefaultFontProviderForPdfA(PdfDocument document, ConverterProperties properties) {
if (document instanceof PdfADocument) {
if (properties == null) {
properties = new ConverterProperties();
}
if (properties.getFontProvider() == null) {
properties.setFontProvider(new DefaultFontProvider(false, true, false));
}
} else if (document == null && properties != null && properties.getConformanceLevel() != null) {
if (properties.getFontProvider() == null) {
properties.setFontProvider(new DefaultFontProvider(false, true, false));
}
}
return properties;
}

private static class HtmlMetaInfo implements IMetaInfo {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down Expand Up @@ -30,9 +30,9 @@ This file is part of the iText (R) project.
*/
public final class PdfHtmlProductData {
private static final String PDF_HTML_PUBLIC_PRODUCT_NAME = "pdfHTML";
private static final String PDF_HTML_VERSION = "5.0.2";
private static final String PDF_HTML_VERSION = "5.0.3";
private static final int PDF_HTML_COPYRIGHT_SINCE = 2000;
private static final int PDF_HTML_COPYRIGHT_TO = 2023;
private static final int PDF_HTML_COPYRIGHT_TO = 2024;

private static final ProductData PDF_HTML_PRODUCT_DATA = new ProductData(PDF_HTML_PUBLIC_PRODUCT_NAME,
ProductNameConstant.PDF_HTML, PDF_HTML_VERSION, PDF_HTML_COPYRIGHT_SINCE, PDF_HTML_COPYRIGHT_TO);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/itextpdf/html2pdf/attach/Attacher.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/itextpdf/html2pdf/attach/ITagWorker.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
Loading

0 comments on commit 2d2556e

Please sign in to comment.