Skip to content

Commit 1364dfb

Browse files
committed
[RELEASE] iText 7 pdfHTML - 2.0.2
https://github.com/itext/i7j-pdfhtml/releases/tag/2.0.2 * release/2.0.2: [RELEASE] 2.0.2-SNAPSHOT -> 2.0.2 Add new uri resolver tests. Add new tests for border radius with dashed borders Add new ignored test for file sharing. Fix html resource for test Fix processing base url as file url. Major refactoring. Add new tests. Add warning logging for attempts of select field acroforms creation Fix issues with text alignment inside select fields Implement support of select, option and optgroup tags Add new tests for height resolving when height and min/max-height props do not conflict Add support for pseudo elements with display:inline-block Add tests for th scopes Support margins, borders and paddings for <body> and <html> tags Update cmp files Add null check for PdfDocument object. DEVSIX-1873 Add ignored test for absolute position Add tests to TagsInsideButtonTest Fix input's min width processing. Introduce radio input element. Fix checkbox and radio processing. Fix cmps. Process input's height properties as they are. Fix content clipping. Minor refactoring. Fix cmps. Fix javadoc Cast ByteBuffer instances to Buffer to solve compatibility issue Add a new test to demonstrate problem with justified text and word/char spacing Add required scope attribute to TH structElements Add tests for CssEmptySelectorTest and CssRootSelectorTest Add problematic tests Add support for buttons with inner tags Add tests for inline-blocks relative width Improve y-line calculation for elements with property overflow:hidden Add support for `a` tag display inline-block; add tests for inline blocks justification Update tests on text alignment applying when text is wrapping around floats Update cmp file Add basic tests for correct block formatting context handling Add new test for collapsing margins and floating elements Update cmp files Disable collapsing margins of page margin box with it's content Reset waitingElement in HtmlDocumentRenderer before triggerring addChild() Add floats with horizontal overflow and nested floats tests, update cmps Avoid matching of all pseudo-classes selector items for custom nodes and document nodes Add support for :empty pseudo-class Add support for :root pseudo-class Extract pseudo class selector item classes to separate class files Add method that inserts single child to jsoup element Open QueryParser class test updated: html2pdf.css.CssNthChildSelectorTest,CssNthOfTypeSelectorTest test updated: com.itextpdf.html2pdf.HyphenateTest test added: com.itextpdf.html2pdf.HtmlCommentedTest Update maven-javadoc-plugin version Fix javadoc Fix applying CSS styles to contents of counter(page(s)) occurred in "content" property Fix overwritten test resoruces Support nth-of-type, first-of-type, last-of-type pseudo-classes. Add new tests. Refactor minor mistypes and make source and destination pathes consistent. Fix page context features tagging, add tests Add tests with media queries for eliminating discrepancy between browser and pdfHTML rendering Fix floating elements inside links handling, add tests Make running elements empty inline-blocks instead of empty blocks Implement running elements support Fix handling of initial value for border-color properties Fix blocks display passing to other workers from ALinkTagWorker Add a test related to NPE while button rendering. Minor fixes in a view of c# port. Support input tag with "checkbox" type. Add a test. Fix some cmps. Process cellpadding attrubute. Set default border-spacing. Fix cmps. Map dotted border style with round dotted border. Fix cmps. Implement border-collapse. Fix cmps. Add a new forced placement test. Add test: html2pdf.element.TaggedPdfFormTest [RELEASE] 2.0.1-SNAPSHOT -> 2.0.2-SNAPSHOT Fix autoport Fix min-max width calculation for input fields Use correct pdfHTML version in comment Textarea, input, button improvements Add test for different display for form tags Add form fields directly to div Refactor baseline calculations for form fields Signed-off-by: iText Software (Community) <[email protected]>
2 parents dec8dac + 580497a commit 1364dfb

File tree

948 files changed

+17802
-1003
lines changed

Some content is hidden

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

948 files changed

+17802
-1003
lines changed

pom.xml

Lines changed: 3 additions & 3 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.1</version>
8+
<version>7.1.2</version>
99
<relativePath />
1010
</parent>
1111

1212
<artifactId>html2pdf</artifactId>
13-
<version>2.0.1</version>
13+
<version>2.0.2</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
@@ -19,7 +19,7 @@
1919

2020
<properties>
2121
<itext.version>${project.parent.version}</itext.version>
22-
<javadoc.version>2.10.4</javadoc.version>
22+
<javadoc.version>3.0.0</javadoc.version>
2323
</properties>
2424

2525
<repositories>

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
This file is part of the iText (R) project.
33
Copyright (c) 1998-2017 iText Group NV
44
Authors: Bruno Lowagie, Paulo Soares, et al.
5-
5+
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU Affero General Public License version 3
88
as published by the Free Software Foundation with the addition of the
99
following permission added to Section 15 as permitted in Section 7(a):
1010
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
1111
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
1212
OF THIRD PARTY RIGHTS
13-
13+
1414
This program is distributed in the hope that it will be useful, but
1515
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1616
or FITNESS FOR A PARTICULAR PURPOSE.
@@ -20,23 +20,23 @@ This file is part of the iText (R) project.
2020
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
2121
Boston, MA, 02110-1301 USA, or download the license from the following URL:
2222
http://itextpdf.com/terms-of-use/
23-
23+
2424
The interactive user interfaces in modified source and object code versions
2525
of this program must display Appropriate Legal Notices, as required under
2626
Section 5 of the GNU Affero General Public License.
27-
27+
2828
In accordance with Section 7(b) of the GNU Affero General Public License,
2929
a covered work must retain the producer line in every PDF that is created
3030
or manipulated using iText.
31-
31+
3232
You can be released from the requirements of the license by purchasing
3333
a commercial license. Buying such a license is mandatory as soon as you
3434
develop commercial activities involving the iText software without
3535
disclosing the source code of your own applications.
3636
These activities include: offering paid services to customers as an ASP,
3737
serving PDFs on the fly in a web application, shipping iText with a closed
3838
source product.
39-
39+
4040
For more information, please contact iText Software Corp. at this
4141
4242
*/
@@ -56,16 +56,15 @@ This file is part of the iText (R) project.
5656
import java.lang.reflect.Array;
5757
import java.lang.reflect.Constructor;
5858
import java.lang.reflect.Method;
59-
import com.itextpdf.html2pdf.Html2PdfProductInfo;
6059
import com.itextpdf.kernel.Version;
6160

62-
import java.io.ByteArrayInputStream;
6361
import java.io.File;
6462
import java.io.FileInputStream;
6563
import java.io.FileOutputStream;
6664
import java.io.IOException;
6765
import java.io.InputStream;
6866
import java.io.OutputStream;
67+
import java.nio.file.Paths;
6968
import java.util.List;
7069

7170
/**
@@ -172,9 +171,9 @@ public static void convertToPdf(File htmlFile, File pdfFile) throws IOException
172171
*/
173172
public static void convertToPdf(File htmlFile, File pdfFile, ConverterProperties converterProperties) throws IOException {
174173
if (converterProperties == null) {
175-
converterProperties = new ConverterProperties().setBaseUri(FileUtil.getParentDirectory(htmlFile.getAbsolutePath()) + File.separator);
174+
converterProperties = new ConverterProperties().setBaseUri(Paths.get(FileUtil.getParentDirectory(htmlFile.getAbsolutePath())).toUri().toURL().toExternalForm() + File.separator);
176175
} else if (converterProperties.getBaseUri() == null) {
177-
converterProperties = new ConverterProperties(converterProperties).setBaseUri(FileUtil.getParentDirectory(htmlFile.getAbsolutePath()) + File.separator);
176+
converterProperties = new ConverterProperties(converterProperties).setBaseUri(Paths.get(FileUtil.getParentDirectory(htmlFile.getAbsolutePath())).toUri().toURL().toExternalForm() + File.separator);
178177
}
179178
try (FileInputStream fileInputStream = new FileInputStream(htmlFile.getAbsolutePath());
180179
FileOutputStream fileOutputStream = new FileOutputStream(pdfFile.getAbsolutePath())) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ This file is part of the iText (R) project.
4747
*/
4848
public final class LogMessageConstant {
4949

50+
/** The Constant ACROFORM_NOT_SUPPORTED_FOR_SELECT. */
51+
public static final String ACROFORM_NOT_SUPPORTED_FOR_SELECT = "AcroForm fields creation for select fields (ComboBoxField and ListBoxField) is not supported. They will be flattened instead.";
5052
/** The Constant CONTENT_PROPERTY_INVALID. */
5153
public static final String CONTENT_PROPERTY_INVALID = "Content property \"{0}\" is either invalid or uses unsupported function.";
5254
/** The Constant CSS_PROPERTY_IN_PERCENTS_NOT_SUPPORTED. */
@@ -76,6 +78,8 @@ public final class LogMessageConstant {
7678
public static final String MARGIN_VALUE_IN_PERCENT_NOT_SUPPORTED = "Margin value in percents not supported";
7779
/** The Constant NOT_SUPPORTED_LIST_STYLE_TYPE. */
7880
public static final String NOT_SUPPORTED_LIST_STYLE_TYPE = "Not supported list style type: {0}";
81+
/** The Constant NOT_SUPPORTED_TH_SCOPE_TYPE. */
82+
public static final String NOT_SUPPORTED_TH_SCOPE_TYPE = "Not supported th scope type: {0}. Document may not be compliant with PDF/UA standards.";
7983
/** The Constant NO_CONSUMER_FOUND_FOR_CONTENT. */
8084
public static final String NO_CONSUMER_FOUND_FOR_CONTENT = "No consumer found for content";
8185
/** The Constant NO_CSS_APPLIER_FOUND_FOR_TAG. */

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
This file is part of the iText (R) project.
33
Copyright (c) 1998-2017 iText Group NV
44
Authors: Bruno Lowagie, Paulo Soares, et al.
5-
5+
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU Affero General Public License version 3
88
as published by the Free Software Foundation with the addition of the
99
following permission added to Section 15 as permitted in Section 7(a):
1010
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
1111
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
1212
OF THIRD PARTY RIGHTS
13-
13+
1414
This program is distributed in the hope that it will be useful, but
1515
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1616
or FITNESS FOR A PARTICULAR PURPOSE.
@@ -20,23 +20,23 @@ This file is part of the iText (R) project.
2020
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
2121
Boston, MA, 02110-1301 USA, or download the license from the following URL:
2222
http://itextpdf.com/terms-of-use/
23-
23+
2424
The interactive user interfaces in modified source and object code versions
2525
of this program must display Appropriate Legal Notices, as required under
2626
Section 5 of the GNU Affero General Public License.
27-
27+
2828
In accordance with Section 7(b) of the GNU Affero General Public License,
2929
a covered work must retain the producer line in every PDF that is created
3030
or manipulated using iText.
31-
31+
3232
You can be released from the requirements of the license by purchasing
3333
a commercial license. Buying such a license is mandatory as soon as you
3434
develop commercial activities involving the iText software without
3535
disclosing the source code of your own applications.
3636
These activities include: offering paid services to customers as an ASP,
3737
serving PDFs on the fly in a web application, shipping iText with a closed
3838
source product.
39-
39+
4040
For more information, please contact iText Software Corp. at this
4141
4242
*/
@@ -52,6 +52,7 @@ This file is part of the iText (R) project.
5252
import com.itextpdf.html2pdf.css.resolve.CssContext;
5353
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
5454
import com.itextpdf.html2pdf.resolver.form.FormFieldNameResolver;
55+
import com.itextpdf.html2pdf.resolver.form.RadioCheckResolver;
5556
import com.itextpdf.html2pdf.resolver.resource.ResourceResolver;
5657
import com.itextpdf.io.font.FontProgram;
5758
import com.itextpdf.kernel.pdf.PdfDocument;
@@ -66,42 +67,45 @@ public class ProcessorContext {
6667

6768
/** The font provider. */
6869
private FontProvider fontProvider;
69-
70+
7071
/** Temporary set of fonts used in the PDF. */
7172
private FontSet tempFonts;
72-
73+
7374
/** The resource resolver. */
7475
private ResourceResolver resourceResolver;
75-
76+
7677
/** The device description. */
7778
private MediaDeviceDescription deviceDescription;
78-
79+
7980
/** The tag worker factory. */
8081
private ITagWorkerFactory tagWorkerFactory;
81-
82+
8283
/** The CSS applier factory. */
8384
private ICssApplierFactory cssApplierFactory;
84-
85+
8586
/** The base URI. */
8687
private String baseUri;
87-
88+
8889
/** Indicates whether an AcroForm needs to be created. */
8990
private boolean createAcroForm;
90-
91+
9192
/** The form field name resolver. */
9293
private FormFieldNameResolver formFieldNameResolver;
93-
94+
95+
/** The radio check resolver. */
96+
private RadioCheckResolver radioCheckResolver;
97+
9498
/** The outline handler. */
9599
private OutlineHandler outlineHandler;
96100

97101
/** Indicates whether the document should be opened in immediate flush or not **/
98102
private boolean immediateFlush;
99103

100104
// Variable fields
101-
105+
102106
/** The state. */
103107
private State state;
104-
108+
105109
/** The CSS context. */
106110
private CssContext cssContext;
107111

@@ -159,6 +163,7 @@ public ProcessorContext(ConverterProperties converterProperties) {
159163

160164
createAcroForm = converterProperties.isCreateAcroForm();
161165
formFieldNameResolver = new FormFieldNameResolver();
166+
radioCheckResolver = new RadioCheckResolver();
162167
immediateFlush = converterProperties.isImmediateFlush();
163168
}
164169

@@ -279,6 +284,16 @@ public FormFieldNameResolver getFormFieldNameResolver() {
279284
return formFieldNameResolver;
280285
}
281286

287+
/**
288+
* Gets the radio check resolver.
289+
*
290+
* @return the radio check resolver
291+
*/
292+
public RadioCheckResolver getRadioCheckResolver() {
293+
return radioCheckResolver;
294+
}
295+
296+
282297
/**
283298
* Gets the outline handler.
284299
*
@@ -366,5 +381,4 @@ public String getBaseUri(){
366381
public boolean isImmediateFlush(){
367382
return immediateFlush;
368383
}
369-
370384
}

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

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ This file is part of the iText (R) project.
4949
import com.itextpdf.html2pdf.attach.ITagWorker;
5050
import com.itextpdf.html2pdf.attach.ProcessorContext;
5151
import com.itextpdf.html2pdf.attach.impl.layout.HtmlDocumentRenderer;
52+
import com.itextpdf.html2pdf.attach.impl.layout.RunningElementContainer;
53+
import com.itextpdf.html2pdf.attach.impl.tags.RunningElementTagWorker;
5254
import com.itextpdf.html2pdf.attach.impl.tags.HtmlTagWorker;
5355
import com.itextpdf.html2pdf.attach.util.LinkHelper;
5456
import com.itextpdf.html2pdf.css.CssConstants;
@@ -76,7 +78,6 @@ This file is part of the iText (R) project.
7678
import java.lang.reflect.Array;
7779
import java.lang.reflect.Constructor;
7880
import java.lang.reflect.Method;
79-
import com.itextpdf.html2pdf.Html2PdfProductInfo;
8081
import com.itextpdf.kernel.Version;
8182
import org.slf4j.Logger;
8283
import org.slf4j.LoggerFactory;
@@ -305,6 +306,8 @@ private void visit(INode node) {
305306
context.getOutlineHandler().addOutline(tagWorker, element, context);
306307

307308
visitPseudoElement(element, CssConstants.BEFORE);
309+
if (element.name().equals(TagConstants.BODY) || element.name().equals(TagConstants.HTML))
310+
runApplier(element, tagWorker);
308311
for (INode childNode : element.childNodes()) {
309312
visit(childNode);
310313
}
@@ -316,17 +319,11 @@ private void visit(INode node) {
316319
context.getOutlineHandler().addDestination(tagWorker, element);
317320
context.getState().pop();
318321

319-
ICssApplier cssApplier = context.getCssApplierFactory().getCssApplier(element);
320-
if (cssApplier == null) {
321-
if (!ignoredCssTags.contains(element.name())) {
322-
logger.error(MessageFormatUtil.format(LogMessageConstant.NO_CSS_APPLIER_FOUND_FOR_TAG, element.name()));
323-
}
324-
} else {
325-
cssApplier.apply(context, element, tagWorker);
326-
}
327-
322+
if (!element.name().equals(TagConstants.BODY) && !element.name().equals(TagConstants.HTML))
323+
runApplier(element, tagWorker);
328324
if (!context.getState().empty()) {
329325
PageBreakApplierUtil.addPageBreakElementBefore(context, context.getState().top(), element, tagWorker);
326+
tagWorker = processRunningElement(tagWorker, element, context);
330327
boolean childProcessed = context.getState().top().processTagChild(tagWorker, context);
331328
PageBreakApplierUtil.addPageBreakElementAfter(context, context.getState().top(), element, tagWorker);
332329
if (!childProcessed && !ignoredChildTags.contains(element.name())) {
@@ -357,6 +354,54 @@ private void visit(INode node) {
357354
}
358355
}
359356

357+
private void runApplier(IElementNode element, ITagWorker tagWorker) {
358+
ICssApplier cssApplier = context.getCssApplierFactory().getCssApplier(element);
359+
if (cssApplier == null) {
360+
if (!ignoredCssTags.contains(element.name())) {
361+
logger.error(MessageFormatUtil.format(LogMessageConstant.NO_CSS_APPLIER_FOUND_FOR_TAG, element.name()));
362+
}
363+
} else {
364+
cssApplier.apply(context, element, tagWorker);
365+
}
366+
}
367+
368+
private ITagWorker processRunningElement(ITagWorker tagWorker, IElementNode element, ProcessorContext context) {
369+
String runningPrefix = CssConstants.RUNNING + "(";
370+
String positionVal;
371+
int endBracketInd;
372+
if (element.getStyles() == null
373+
|| (positionVal = element.getStyles().get(CssConstants.POSITION)) == null
374+
|| !positionVal.startsWith(runningPrefix)
375+
// closing bracket should be there and there should be at least one symbol between brackets
376+
|| (endBracketInd = positionVal.indexOf(")")) <= runningPrefix.length()) {
377+
return tagWorker;
378+
}
379+
380+
String runningElemName = positionVal.substring(runningPrefix.length(), endBracketInd).trim();
381+
if (runningElemName.isEmpty()) {
382+
return tagWorker;
383+
}
384+
385+
// TODO For now the whole ITagWorker of the running element is preserved inside RunningElementContainer
386+
// for the sake of future processing in page margin box. This is somewhat a workaround and storing
387+
// tag workers might be easily seen as something undesirable, however at least for now it seems to be
388+
// most suitable solution because:
389+
// - in any case, processing of the whole running element with it's children should be done in
390+
// "normal flow", i.e. in DefaultHtmlProcessor, based on the spec that says that element should be
391+
// processed as it was still in the same position in DOM, but visually as if "display: none" was set.
392+
// - the whole process would need to be repeated in PageContextProcessor again, so it's a double work;
393+
// also currently there is still no convenient way for unifying the processing here and in
394+
// PageContextProcessor, currently only running elements require processing of the whole hierarchy of
395+
// children outside of the default DOM processing and also it's unclear whether this code would be suitable
396+
// for the simplified approach of processing all other children of page margin boxes.
397+
// - ITagWorker is only publicly passed to the constructor, but there is no exposed way to get it out of
398+
// RunningElementContainer, so it would be fairly easy to change this approach in future if needed.
399+
RunningElementContainer runningElementContainer = new RunningElementContainer(element, tagWorker);
400+
context.getCssContext().getRunningManager().addRunningElement(runningElemName, runningElementContainer);
401+
402+
return new RunningElementTagWorker(runningElementContainer);
403+
}
404+
360405
/**
361406
* Adds @font-face fonts to the FontProvider.
362407
*/

0 commit comments

Comments
 (0)