Skip to content

Commit 8edebb2

Browse files
committed
[RELEASE] iText 7 pdfHTML - 3.0.0
https://github.com/itext/i7j-pdfhtml/releases/tag/3.0.0 * release/3.0.0: [RELEASE] 3.0.0-SNAPSHOT -> 3.0.0 Revise destination name generation mechanism when building outlines Remove redundant throws declarations Remove deprecated code Remove redundant interface extension for form field classes Remove gpl font license Add monospace tests Adjust page margin fonts tests Update misc cmp files Update test with special cases Update page margin tests Changed free fonts to noto fonts. Add NOTICE file Remove HTML mode setting in tests Enable HTML mode, update cmp files Make <page-size> ledger portrait-oriented Bump pdfHTML snapshot version to 3.0.0-SNAPSHOT. Block pipeline on Java builds only of iText Core Fix 'findFiles refers to incorrect path' Performance improvements of Jenkins builds Remove redundant FORCED_PLACEMENT check. Fix upload of jar files to Artifactory Add TODO to support link tags processing Add a default mode property for a running element Deprecate the constant RULE_IS_NOT_SUPPORTED Add missing copyright headers Support css orphans and widows properties Refactor references to deprecated constructor Add DEVSIX mention within Ignore Revert to typo_ascender scale coefficient usage for Type1Fonts for HTML mode Add test for linebox min height for line-height:normal Support line-height property and add tests Add AlignAttributeTest#imgAttrAlignLeftReadOrderPdfTest Add a test which demonstrates an NPE while tagging a button Change output formatting Add HtmlPageMarginBoxImageSizeTest Remove FontSelectorPerformanceTest Remove manual test ResourceResolverTest17 Add missing copyright headers Fix minor mistype in WidthDimensionContainer. Add unit test for minContentDimension Add missing copyright headers Improve logic of creating destination name and update JavaDoc [RELEASE] Update dependency versions Add missing copyright headers Extract an inline constant from FontStyleApplierUtil to a class's final field Run package phase for faster Artifactory deploy Add OWASP dependency check Run non-test phases of the Maven lifecycle multithreaded Replace Findbugs with Spotbugs Refactor nested if to switch in Pipeline
2 parents d6a59bc + 87505b4 commit 8edebb2

File tree

2,457 files changed

+5543
-5567
lines changed

Some content is hidden

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

2,457 files changed

+5543
-5567
lines changed

Jenkinsfile

Lines changed: 105 additions & 60 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
4+
45
<parent>
56
<groupId>com.itextpdf</groupId>
67
<artifactId>root</artifactId>
7-
<version>7.1.10</version>
8+
<version>7.1.11</version>
89
<relativePath/>
910
</parent>
11+
1012
<artifactId>html2pdf</artifactId>
11-
<version>2.1.7</version>
13+
<version>3.0.0</version>
14+
1215
<name>pdfHTML</name>
1316
<description>pdfHTML is an iText 7 add-on that lets you to parse (X)HTML snippets and the associated CSS and converts
1417
them to PDF.</description>
18+
1519
<scm>
1620
<connection>scm:git:ssh://[email protected]:7999/i7j/html2pdf.git</connection>
1721
<url>https://git.itextsupport.com/projects/I7J/repos/html2pdf</url>
1822
</scm>
23+
1924
<properties>
2025
<itext.version>${project.parent.version}</itext.version>
2126
</properties>
27+
2228
<repositories>
2329
<repository>
2430
<snapshots>
@@ -37,6 +43,7 @@
3743
<url>https://repo.itextsupport.com/releases</url>
3844
</repository>
3945
</repositories>
46+
4047
<dependencies>
4148
<dependency>
4249
<groupId>com.itextpdf</groupId>
@@ -72,6 +79,7 @@
7279
<scope>test</scope>
7380
</dependency>
7481
</dependencies>
82+
7583
<build>
7684
<resources>
7785
<resource>
@@ -90,25 +98,7 @@
9098
</resources>
9199
<plugins>
92100
<plugin>
93-
<groupId>external.atlassian.jgitflow</groupId>
94-
<artifactId>jgitflow-maven-plugin</artifactId>
95-
<version>1.0-m5.1</version>
96-
</plugin>
97-
<plugin>
98-
<groupId>org.apache.maven.plugins</groupId>
99-
<artifactId>maven-failsafe-plugin</artifactId>
100-
<version>${failsafe.version}</version>
101-
<configuration>
102-
<includes>
103-
<include>**/*.java</include>
104-
</includes>
105-
<groups>${integrationtests}</groups>
106-
</configuration>
107-
</plugin>
108-
<plugin>
109-
<groupId>org.apache.maven.plugins</groupId>
110101
<artifactId>maven-javadoc-plugin</artifactId>
111-
<version>${javadoc.version}</version>
112102
<configuration>
113103
<sourceFileExcludes>
114104
<sourceFileExclude>com/itextpdf/html2pdf/attach/impl/layout/BodyHtmlStylesContainer.java</sourceFileExclude>
@@ -124,30 +114,6 @@
124114
</groups>
125115
</configuration>
126116
</plugin>
127-
<plugin>
128-
<groupId>org.apache.maven.plugins</groupId>
129-
<artifactId>maven-surefire-plugin</artifactId>
130-
<version>${surefire.version}</version>
131-
<configuration>
132-
<groups>${unittests}</groups>
133-
</configuration>
134-
</plugin>
135-
<plugin>
136-
<groupId>org.pitest</groupId>
137-
<artifactId>pitest-maven</artifactId>
138-
<version>1.1.11</version>
139-
<configuration>
140-
<skip>true</skip>
141-
</configuration>
142-
</plugin>
143-
<plugin>
144-
<groupId>org.revapi</groupId>
145-
<artifactId>revapi-maven-plugin</artifactId>
146-
<version>0.8.2</version>
147-
<configuration>
148-
<skip>true</skip>
149-
</configuration>
150-
</plugin>
151117
</plugins>
152118
</build>
153119
</project>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public class Html2PdfProductInfo {
5353
public static final String PRODUCT_NAME = "pdfHtml";
5454

5555
/** The major version number. */
56-
public static final int MAJOR_VERSION = 2;
56+
public static final int MAJOR_VERSION = 3;
5757

5858
/** The minor version number. */
59-
public static final int MINOR_VERSION = 1;
59+
public static final int MINOR_VERSION = 0;
6060
}

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

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ This file is part of the iText (R) project.
4646
import com.itextpdf.html2pdf.attach.Attacher;
4747
import com.itextpdf.html2pdf.exception.Html2PdfException;
4848
import com.itextpdf.io.util.FileUtil;
49+
import com.itextpdf.kernel.Version;
4950
import com.itextpdf.kernel.counter.event.IMetaInfo;
5051
import com.itextpdf.kernel.pdf.DocumentProperties;
5152
import com.itextpdf.kernel.pdf.PdfDocument;
5253
import com.itextpdf.kernel.pdf.PdfWriter;
5354
import com.itextpdf.layout.Document;
5455
import com.itextpdf.layout.element.IElement;
55-
import java.lang.reflect.Array;
56-
import java.lang.reflect.Constructor;
57-
import java.lang.reflect.Method;
58-
import com.itextpdf.kernel.Version;
5956
import com.itextpdf.styledxmlparser.IXmlParser;
6057
import com.itextpdf.styledxmlparser.node.IDocumentNode;
6158
import com.itextpdf.styledxmlparser.node.impl.jsoup.JsoupHtmlParser;
@@ -66,6 +63,9 @@ This file is part of the iText (R) project.
6663
import java.io.IOException;
6764
import java.io.InputStream;
6865
import java.io.OutputStream;
66+
import java.lang.reflect.Array;
67+
import java.lang.reflect.Constructor;
68+
import java.lang.reflect.Method;
6969
import java.util.List;
7070

7171
/**
@@ -92,9 +92,8 @@ private HtmlConverter() {
9292
*
9393
* @param html the html in the form of a {@link String}
9494
* @param pdfStream the PDF as an {@link OutputStream}
95-
* @throws IOException Signals that an I/O exception has occurred.
9695
*/
97-
public static void convertToPdf(String html, OutputStream pdfStream) throws IOException {
96+
public static void convertToPdf(String html, OutputStream pdfStream) {
9897
convertToPdf(html, pdfStream, null);
9998
}
10099

@@ -105,9 +104,8 @@ public static void convertToPdf(String html, OutputStream pdfStream) throws IOEx
105104
* @param html the html in the form of a {@link String}
106105
* @param pdfStream the PDF as an {@link OutputStream}
107106
* @param converterProperties a {@link ConverterProperties} instance
108-
* @throws IOException Signals that an I/O exception has occurred.
109107
*/
110-
public static void convertToPdf(String html, OutputStream pdfStream, ConverterProperties converterProperties) throws IOException {
108+
public static void convertToPdf(String html, OutputStream pdfStream, ConverterProperties converterProperties) {
111109
convertToPdf(html, new PdfWriter(pdfStream), converterProperties);
112110
}
113111

@@ -117,9 +115,8 @@ public static void convertToPdf(String html, OutputStream pdfStream, ConverterPr
117115
*
118116
* @param html the html in the form of a {@link String}
119117
* @param pdfWriter the {@link PdfWriter} instance
120-
* @throws IOException Signals that an I/O exception has occurred.
121118
*/
122-
public static void convertToPdf(String html, PdfWriter pdfWriter) throws IOException {
119+
public static void convertToPdf(String html, PdfWriter pdfWriter) {
123120
convertToPdf(html, pdfWriter, null);
124121
}
125122

@@ -130,9 +127,8 @@ public static void convertToPdf(String html, PdfWriter pdfWriter) throws IOExcep
130127
* @param html the html in the form of a {@link String}
131128
* @param pdfWriter the {@link PdfWriter} instance
132129
* @param converterProperties a {@link ConverterProperties} instance
133-
* @throws IOException Signals that an I/O exception has occurred.
134130
*/
135-
public static void convertToPdf(String html, PdfWriter pdfWriter, ConverterProperties converterProperties) throws IOException {
131+
public static void convertToPdf(String html, PdfWriter pdfWriter, ConverterProperties converterProperties) {
136132
convertToPdf(html, new PdfDocument(pdfWriter, new DocumentProperties().setEventCountingMetaInfo(new HtmlMetaInfo())), converterProperties);
137133
}
138134

@@ -143,9 +139,8 @@ public static void convertToPdf(String html, PdfWriter pdfWriter, ConverterPrope
143139
* @param html the html in the form of a {@link String}
144140
* @param pdfDocument the {@link PdfDocument} instance
145141
* @param converterProperties a {@link ConverterProperties} instance
146-
* @throws IOException Signals that an I/O exception has occurred.
147142
*/
148-
public static void convertToPdf(String html, PdfDocument pdfDocument, ConverterProperties converterProperties) throws IOException {
143+
public static void convertToPdf(String html, PdfDocument pdfDocument, ConverterProperties converterProperties) {
149144
Document document = convertToDocument(html, pdfDocument, converterProperties);
150145
document.close();
151146
}
@@ -268,9 +263,8 @@ public static void convertToPdf(InputStream htmlStream, PdfDocument pdfDocument,
268263
* @param html the html in the form of a {@link String}
269264
* @param pdfWriter the {@link PdfWriter} containing the resulting PDF
270265
* @return a {@link Document} instance
271-
* @throws IOException Signals that an I/O exception has occurred.
272266
*/
273-
public static Document convertToDocument(String html, PdfWriter pdfWriter) throws IOException {
267+
public static Document convertToDocument(String html, PdfWriter pdfWriter) {
274268
return convertToDocument(html, pdfWriter, null);
275269
}
276270

@@ -296,9 +290,8 @@ public static Document convertToDocument(InputStream htmlStream, PdfWriter pdfWr
296290
* @param pdfWriter the pdf writer
297291
* @param converterProperties a {@link ConverterProperties} instance
298292
* @return a {@link Document} instance
299-
* @throws IOException Signals that an I/O exception has occurred.
300293
*/
301-
public static Document convertToDocument(String html, PdfWriter pdfWriter, ConverterProperties converterProperties) throws IOException {
294+
public static Document convertToDocument(String html, PdfWriter pdfWriter, ConverterProperties converterProperties) {
302295
return convertToDocument(html, new PdfDocument(pdfWriter), converterProperties);
303296
}
304297

@@ -326,9 +319,8 @@ public static Document convertToDocument(InputStream htmlStream, PdfWriter pdfWr
326319
* @param pdfDocument the {@link PdfDocument} instance
327320
* @param converterProperties a {@link ConverterProperties} instance
328321
* @return a {@link Document} instance
329-
* @throws IOException Signals that an I/O exception has occurred.
330322
*/
331-
public static Document convertToDocument(String html, PdfDocument pdfDocument, ConverterProperties converterProperties) throws IOException {
323+
public static Document convertToDocument(String html, PdfDocument pdfDocument, ConverterProperties converterProperties) {
332324
String licenseKeyClassName = "com.itextpdf.licensekey.LicenseKey";
333325
String licenseKeyProductClassName = "com.itextpdf.licensekey.LicenseKeyProduct";
334326
String licenseKeyFeatureClassName = "com.itextpdf.licensekey.LicenseKeyProductFeature";
@@ -435,9 +427,8 @@ public static Document convertToDocument(InputStream htmlStream, PdfDocument pdf
435427
*
436428
* @param html the html in the form of a {@link String}
437429
* @return a list of iText building blocks
438-
* @throws IOException Signals that an I/O exception has occurred.
439430
*/
440-
public static List<IElement> convertToElements(String html) throws IOException {
431+
public static List<IElement> convertToElements(String html) {
441432
return convertToElements(html, null);
442433
}
443434

@@ -461,9 +452,8 @@ public static List<IElement> convertToElements(InputStream htmlStream) throws IO
461452
* @param html the html in the form of a {@link String}
462453
* @param converterProperties a {@link ConverterProperties} instance
463454
* @return a list of iText building blocks
464-
* @throws IOException Signals that an I/O exception has occurred.
465455
*/
466-
public static List<IElement> convertToElements(String html, ConverterProperties converterProperties) throws IOException {
456+
public static List<IElement> convertToElements(String html, ConverterProperties converterProperties) {
467457
String licenseKeyClassName = "com.itextpdf.licensekey.LicenseKey";
468458
String licenseKeyProductClassName = "com.itextpdf.licensekey.LicenseKeyProduct";
469459
String licenseKeyFeatureClassName = "com.itextpdf.licensekey.LicenseKeyProductFeature";

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,8 @@ public final class LogMessageConstant {
6565
public static final String ERROR_WHILE_LAYOUT_OF_FORM_FIELD = "Cannot layout form field field. It won't be displayed";
6666
/** The Constant ERROR_WHILE_LAYOUT_OF_FORM_FIELD_WITH_TYPE. */
6767
public static final String ERROR_WHILE_LAYOUT_OF_FORM_FIELD_WITH_TYPE = "Error during layout of form filed with type {0}.";
68-
/** The Constant HEIGHT_VALUE_IN_PERCENT_NOT_SUPPORTED. */
69-
@Deprecated
70-
public static final String HEIGHT_VALUE_IN_PERCENT_NOT_SUPPORTED = "Height value in percent not supported";
7168
/** The Constant INPUT_FIELD_DOES_NOT_FIT. */
7269
public static final String INPUT_FIELD_DOES_NOT_FIT = "Input field doesn't fit in outer object. It will be clipped";
73-
/** The Constant INPUT_SUPPORTS_ONLY_POINT_WIDTH. */
74-
@Deprecated
75-
public static final String INPUT_SUPPORTS_ONLY_POINT_WIDTH = "Input field supports only point width";
7670
/** The Constant INPUT_TYPE_IS_INVALID. */
7771
public static final String INPUT_TYPE_IS_INVALID = "Input type {0} is invalid. The default text type will be used instead.";
7872
/** The Constant INPUT_TYPE_IS_NOT_SUPPORTED. */
@@ -103,22 +97,14 @@ public final class LogMessageConstant {
10397
public static final String PDF_DOCUMENT_NOT_PRESENT = "PdfDocument is not present";
10498
/** The Constant QUOTES_PROPERTY_INVALID. */
10599
public static final String QUOTES_PROPERTY_INVALID = "Quote property \"{0}\" is invalid. It should contain even number of <string> values.";
106-
/** The Constant RULE_IS_NOT_SUPPORTED. */
107-
public static final String RULE_IS_NOT_SUPPORTED = "The rule @{0} is unsupported. All selectors in this rule will be ignored.";
108100
/** The Constant TEXT_DECORATION_BLINK_NOT_SUPPORTED. */
109101
public static final String TEXT_DECORATION_BLINK_NOT_SUPPORTED = "text-decoration: blink not supported";
110-
/** The Constant TEXT_WAS_NOT_PROCESSED. */
111-
@Deprecated
112-
public static final String TEXT_WAS_NOT_PROCESSED = "Text was not processed: {0}";
113102
/** The Constant UNABLE_TO_PROCESS_EXTERNAL_CSS_FILE. */
114103
public static final String UNABLE_TO_PROCESS_EXTERNAL_CSS_FILE = "Unable to process external css file";
115104
/** The Constant UNABLE_TO_PROCESS_IMAGE_AS_SVG */
116105
public static final String UNABLE_TO_PROCESS_IMAGE_AS_SVG = "Unable to process image found at {0} as an SVG";
117106
/** The Constant UNABLE_TO_RESOLVE_COUNTER. */
118107
public static final String UNABLE_TO_RESOLVE_COUNTER = "Unable to resolve counter \"{0}\"";
119-
/** The Constant UNABLE_TO_RESOLVE_FONT. */
120-
@Deprecated
121-
public static final String UNABLE_TO_RESOLVE_FONT = "Unable to resolve font: {0}. The default one will be used instead";
122108
/** The Constant UNABLE_TO_RETRIEVE_FONT. */
123109
public static final String UNABLE_TO_RETRIEVE_FONT = "Unable to retrieve font:\n {0}";
124110
/** The Constant UNABLE_TO_RETRIEVE_IMAGE_WITH_GIVEN_BASE_URI. */

src/main/java/com/itextpdf/html2pdf/attach/impl/DefaultHtmlProcessor.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ This file is part of the iText (R) project.
7171
import com.itextpdf.layout.Document;
7272
import com.itextpdf.layout.IPropertyContainer;
7373
import com.itextpdf.layout.element.Div;
74+
import com.itextpdf.layout.font.FontFamilySplitter;
7475
import com.itextpdf.layout.font.FontInfo;
7576
import com.itextpdf.layout.font.Range;
7677
import com.itextpdf.layout.property.Property;
78+
import com.itextpdf.layout.property.RenderingMode;
7779
import com.itextpdf.styledxmlparser.css.CssDeclaration;
7880
import com.itextpdf.styledxmlparser.css.CssFontFaceRule;
7981
import com.itextpdf.styledxmlparser.css.ICssResolver;
@@ -83,6 +85,8 @@ This file is part of the iText (R) project.
8385
import com.itextpdf.styledxmlparser.node.IElementNode;
8486
import com.itextpdf.styledxmlparser.node.INode;
8587
import com.itextpdf.styledxmlparser.node.ITextNode;
88+
89+
import java.util.Map;
8690
import org.slf4j.Logger;
8791
import org.slf4j.LoggerFactory;
8892

@@ -163,6 +167,29 @@ public DefaultHtmlProcessor(ConverterProperties converterProperties) {
163167
this.context = new ProcessorContext(converterProperties);
164168
}
165169

170+
/**
171+
* Sets properties to top-level layout elements converted from HTML.
172+
* This enables features set by user via HTML converter API and also changes properties defaults
173+
* to the ones specific to HTML-like behavior.
174+
* @param cssProperties HTML document-level css properties.
175+
* @param context processor context specific to the current HTML conversion.
176+
* @param propertyContainer top-level layout element converted from HTML.
177+
*/
178+
public static void setConvertedRootElementProperties(Map<String, String> cssProperties, ProcessorContext context, IPropertyContainer propertyContainer) {
179+
propertyContainer.setProperty(Property.COLLAPSING_MARGINS, true);
180+
propertyContainer.setProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
181+
propertyContainer.setProperty(Property.FONT_PROVIDER, context.getFontProvider());
182+
if (context.getTempFonts() != null) {
183+
propertyContainer.setProperty(Property.FONT_SET, context.getTempFonts());
184+
}
185+
186+
// TODO DEVSIX-2534
187+
List<String> fontFamilies = FontFamilySplitter.splitFontFamily(cssProperties.get(CssConstants.FONT_FAMILY));
188+
if (fontFamilies != null && !propertyContainer.hasOwnProperty(Property.FONT)) {
189+
propertyContainer.setProperty(Property.FONT, fontFamilies.toArray(new String[0]));
190+
}
191+
}
192+
166193
/* (non-Javadoc)
167194
* @see com.itextpdf.html2pdf.attach.IHtmlProcessor#processElements(com.itextpdf.html2pdf.html.node.INode)
168195
*/
@@ -220,13 +247,11 @@ public List<com.itextpdf.layout.element.IElement> processElements(INode root) {
220247

221248
Div bodyDiv = (Div) roots.get(0);
222249
List<com.itextpdf.layout.element.IElement> elements = new ArrayList<>();
250+
// re-resolve body element styles in order to use them in top-level elements properties setting
251+
body.setStyles(cssResolver.resolveStyles(body, context.getCssContext()));
223252
for (IPropertyContainer propertyContainer : bodyDiv.getChildren()) {
224253
if (propertyContainer instanceof com.itextpdf.layout.element.IElement) {
225-
propertyContainer.setProperty(Property.COLLAPSING_MARGINS, true);
226-
propertyContainer.setProperty(Property.FONT_PROVIDER, context.getFontProvider());
227-
if (context.getTempFonts() != null) {
228-
propertyContainer.setProperty(Property.FONT_SET, context.getTempFonts());
229-
}
254+
setConvertedRootElementProperties(body.getStyles(), context, propertyContainer);
230255
elements.add((com.itextpdf.layout.element.IElement) propertyContainer);
231256
}
232257
}
@@ -325,7 +350,7 @@ private void visit(INode node) {
325350
((HtmlTagWorker) tagWorker).processPageRules(node, cssResolver, context);
326351
}
327352

328-
context.getOutlineHandler().addOutline(tagWorker, element, context);
353+
context.getOutlineHandler().addOutlineAndDestToDocument(tagWorker, element, context);
329354

330355

331356
visitPseudoElement(element, tagWorker, CssConstants.BEFORE);
@@ -342,7 +367,7 @@ private void visit(INode node) {
342367
if (tagWorker != null) {
343368
tagWorker.processEnd(element, context);
344369
LinkHelper.createDestination(tagWorker, element, context);
345-
context.getOutlineHandler().addDestination(tagWorker, element);
370+
context.getOutlineHandler().setDestinationToElement(tagWorker, element);
346371
context.getState().pop();
347372

348373
if (!TagConstants.BODY.equals(element.name()) && !TagConstants.HTML.equals(element.name()))

0 commit comments

Comments
 (0)