Skip to content

Commit

Permalink
[RELEASE] iText pdfHTML 5.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
iText-CI committed Jul 20, 2023
2 parents b128b3d + bd7af94 commit 353b122
Show file tree
Hide file tree
Showing 2,662 changed files with 59,184 additions and 372 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>8.0.0</version>
<version>8.0.1</version>
<relativePath />
</parent>

<artifactId>html2pdf</artifactId>
<version>5.0.0</version>
<version>5.0.1</version>

<name>pdfHTML</name>
<description>pdfHTML is an iText 7 add-on that lets you to parse (X)HTML snippets and the associated CSS and converts
<description>pdfHTML is an iText add-on that lets you to parse (X)HTML snippets and the associated CSS and converts
them to PDF.</description>

<scm>
Expand Down
19 changes: 19 additions & 0 deletions sharpenConfiguration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
<ignored>
<java>
<fileset reason="The Iterator pattern in Java is equivalent to IEnumerable in .NET, but we cannot map them on each other.">
<file path="com/itextpdf/html2pdf/css/resolve/CssContentElementNode.java"/>
</fileset>
<fileset reason="The ignore is added here because the work with absolute path and URI is not autoportable.">
<file path="com/itextpdf/html2pdf/resolver/resource/PathUtil.java"/>
</fileset>
<fileset reason="Added mto ignored because ExecutorService and usage of Futures are not autoportable">
<file path="com/itextpdf/html2pdf/HtmlConverterMultiThreadedTest.java"/>
</fileset>
</java>
<resource>
<file path="com/itextpdf/html2pdf/css/w3c/css21/text/text-transform-uppercase-002.pdf" />
</resource>
</ignored>
</configuration>
26 changes: 26 additions & 0 deletions src/main/java/com/itextpdf/html2pdf/ConverterProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public class ConverterProperties {
*/
private IMetaInfo metaInfo;

/**
* enables continuous container for all elements.
*/
private boolean continuousContainerEnabled;

/**
* Instantiates a new {@link ConverterProperties} instance.
*/
Expand All @@ -125,6 +130,7 @@ public ConverterProperties(ConverterProperties other) {
this.metaInfo = other.metaInfo;
this.limitOfLayouts = other.limitOfLayouts;
this.immediateFlush = other.immediateFlush;
this.continuousContainerEnabled = other.continuousContainerEnabled;
}

/**
Expand Down Expand Up @@ -440,4 +446,24 @@ public ConverterProperties setEventMetaInfo(IMetaInfo metaInfo) {
this.metaInfo = metaInfo;
return this;
}

/**
* check if continuous container is enabled.
*
* @return true if enabled, false otherwise
*/
public boolean isContinuousContainerEnabled() {
return continuousContainerEnabled;
}

/**
* Sets continuous container support.
*
* @param value true to set continuous container, false otherwise
* @return the {@link ConverterProperties} instance
*/
public ConverterProperties setContinuousContainerEnabled(boolean value) {
continuousContainerEnabled = value;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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.0";
private static final String PDF_HTML_VERSION = "5.0.1";
private static final int PDF_HTML_COPYRIGHT_SINCE = 2000;
private static final int PDF_HTML_COPYRIGHT_TO = 2023;

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/itextpdf/html2pdf/attach/ProcessorContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public class ProcessorContext {

private final int limitOfLayouts;

/**
* enables continuous container for all elements.
*/
private boolean continuousContainerEnabled;

/**
* Instantiates a new {@link ProcessorContext} instance.
*
Expand Down Expand Up @@ -195,6 +200,7 @@ public ProcessorContext(ConverterProperties converterProperties) {
radioCheckResolver = new RadioCheckResolver();
immediateFlush = converterProperties.isImmediateFlush();
processingInlineSvg = false;
continuousContainerEnabled = converterProperties.isContinuousContainerEnabled();
}

/**
Expand Down Expand Up @@ -484,4 +490,14 @@ public void startProcessingInlineSvg() {
public void endProcessingInlineSvg(){
processingInlineSvg = false;
}


/**
* check if continuous container is enabled.
*
* @return true if enabled, false otherwise
*/
public boolean isContinuousContainerEnabled() {
return continuousContainerEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ private void visit(INode node) {
} else if (tagWorker.getElementResult() != null) {
roots.add(tagWorker.getElementResult());
}

if (tagWorker.getElementResult() != null && context.isContinuousContainerEnabled()) {
tagWorker.getElementResult().setProperty(Property.COLLAPSING_MARGINS, Boolean.FALSE);
tagWorker.getElementResult().setProperty(Property.TREAT_AS_CONTINUOUS_CONTAINER, true);
}
}

element.setStyles(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ This file is part of the iText (R) project.
import com.itextpdf.html2pdf.attach.ITagWorkerFactory;
import com.itextpdf.html2pdf.attach.ProcessorContext;
import com.itextpdf.html2pdf.attach.impl.DefaultTagWorkerMapping.ITagWorkerCreator;
import com.itextpdf.html2pdf.util.TagProcessorMapping;
import com.itextpdf.html2pdf.css.CssConstants;
import com.itextpdf.html2pdf.util.TagProcessorMapping;
import com.itextpdf.styledxmlparser.node.IElementNode;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This file is part of the iText (R) project.
import com.itextpdf.layout.element.IElement;
import com.itextpdf.layout.element.ILeafElement;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.MulticolContainer;
import com.itextpdf.styledxmlparser.node.IElementNode;

import java.util.Map;
Expand All @@ -44,6 +45,11 @@ This file is part of the iText (R) project.
*/
public class DivTagWorker implements ITagWorker, IDisplayAware {

/**
* Column container element.
*/
protected MulticolContainer multicolContainer;

/** The div element. */
private Div div;

Expand All @@ -62,6 +68,10 @@ public class DivTagWorker implements ITagWorker, IDisplayAware {
public DivTagWorker(IElementNode element, ProcessorContext context) {
div = new Div();
Map<String, String> styles = element.getStyles();
if (styles != null && (styles.containsKey(CssConstants.COLUMN_COUNT) || styles.containsKey(CssConstants.COLUMN_WIDTH))) {
multicolContainer = new MulticolContainer();
multicolContainer.add(div);
}
inlineHelper = new WaitingInlineElementsHelper(styles == null ? null : styles.get(CssConstants.WHITE_SPACE),
styles == null ? null : styles.get(CssConstants.TEXT_TRANSFORM));
display = element.getStyles() != null ? element.getStyles().get(CssConstants.DISPLAY) : null;
Expand Down Expand Up @@ -132,7 +142,7 @@ public boolean processTagChild(ITagWorker childTagWorker, ProcessorContext conte
*/
@Override
public IPropertyContainer getElementResult() {
return div;
return multicolContainer == null ? div : multicolContainer;
}

/* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public boolean processContent(String content, ProcessorContext context) {
super.processContent(content, context);
}
if (!fakedContent) {
actualOptionTextContent.append(content); // TODO DEVSIX-1901: spaces are not collapsed according to white-space property in here
// TODO DEVSIX-2443: spaces are not collapsed according to white-space property in here
actualOptionTextContent.append(content);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This file is part of the iText (R) project.
import com.itextpdf.layout.element.IElement;
import com.itextpdf.layout.element.ILeafElement;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.MulticolContainer;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.styledxmlparser.node.IElementNode;

Expand All @@ -57,6 +58,11 @@ public class PTagWorker implements ITagWorker, IDisplayAware {
/** The container which handles the elements that are present in the &lt;p&gt; tag. */
private Div elementsContainer;

/**
* Container for the result in case of multicol layouting
*/
protected MulticolContainer multicolContainer;

/** Helper class for waiting inline elements. */
private WaitingInlineElementsHelper inlineHelper;

Expand All @@ -71,6 +77,11 @@ public class PTagWorker implements ITagWorker, IDisplayAware {
*/
public PTagWorker(IElementNode element, ProcessorContext context) {
lastParagraph = new Paragraph();

if (element.getStyles().get(CssConstants.COLUMN_COUNT) != null || element.getStyles().get(CssConstants.COLUMN_WIDTH) != null) {
multicolContainer = new MulticolContainer();
multicolContainer.add(lastParagraph);
}
inlineHelper = new WaitingInlineElementsHelper(element.getStyles().get(CssConstants.WHITE_SPACE),
element.getStyles().get(CssConstants.TEXT_TRANSFORM));
display = element.getStyles() != null ? element.getStyles().get(CssConstants.DISPLAY) : null;
Expand Down Expand Up @@ -151,7 +162,10 @@ public boolean processTagChild(ITagWorker childTagWorker, ProcessorContext conte
*/
@Override
public IPropertyContainer getElementResult() {
return null == elementsContainer ? (IPropertyContainer) lastParagraph : (IPropertyContainer) elementsContainer;
if (multicolContainer == null) {
return null == elementsContainer ? (IPropertyContainer) lastParagraph : (IPropertyContainer) elementsContainer;
}
return multicolContainer;
}

@Override
Expand All @@ -163,6 +177,10 @@ private void processBlockElement(IElement propertyContainer) {
if (elementsContainer == null) {
elementsContainer = new Div();
elementsContainer.add(lastParagraph);
if (multicolContainer != null) {
multicolContainer.getChildren().clear();
multicolContainer.add(elementsContainer);
}
}
inlineHelper.flushHangingLeaves(lastParagraph);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,35 @@ This file is part of the iText (R) project.
import com.itextpdf.forms.form.element.AbstractSelectField;
import com.itextpdf.forms.form.element.ComboBoxField;
import com.itextpdf.forms.form.element.ListBoxField;
import com.itextpdf.forms.form.element.SelectFieldItem;
import com.itextpdf.html2pdf.attach.ITagWorker;
import com.itextpdf.html2pdf.attach.ProcessorContext;
import com.itextpdf.html2pdf.css.CssConstants;
import com.itextpdf.html2pdf.html.AttributeConstants;
import com.itextpdf.html2pdf.logs.Html2PdfLogMessageConstant;
import com.itextpdf.layout.IPropertyContainer;
import com.itextpdf.layout.element.IBlockElement;
import com.itextpdf.html2pdf.html.AttributeConstants;
import com.itextpdf.html2pdf.css.CssConstants;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.styledxmlparser.css.util.CssDimensionParsingUtils;
import com.itextpdf.styledxmlparser.node.IElementNode;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* TagWorker class for the {@code select} element.
*/
public class SelectTagWorker implements ITagWorker, IDisplayAware {

/** The form element. */
private static final Logger LOGGER = LoggerFactory.getLogger(SelectTagWorker.class);
/**
* The form element.
*/
private AbstractSelectField selectElement;

/** The display. */
/**
* The display.
*/
private String display;

/**
Expand All @@ -61,6 +72,12 @@ public SelectTagWorker(IElementNode element, ProcessorContext context) {

if (size > 1 || multipleAttr) {
selectElement = new ListBoxField(name, size, multipleAttr);

// Remove some properties which are set in ListBoxField constructor
selectElement.deleteOwnProperty(Property.PADDING_LEFT);
selectElement.deleteOwnProperty(Property.PADDING_RIGHT);
selectElement.deleteOwnProperty(Property.PADDING_TOP);
selectElement.deleteOwnProperty(Property.PADDING_BOTTOM);
} else {
selectElement = new ComboBoxField(name);
}
Expand All @@ -84,7 +101,16 @@ public boolean processContent(String content, ProcessorContext context) {
public boolean processTagChild(ITagWorker childTagWorker, ProcessorContext context) {
if (childTagWorker instanceof OptionTagWorker || childTagWorker instanceof OptGroupTagWorker) {
if (childTagWorker.getElementResult() instanceof IBlockElement) {
selectElement.addOption((IBlockElement) childTagWorker.getElementResult());
IBlockElement blockElement = (IBlockElement) childTagWorker.getElementResult();
String label = blockElement.<String>getProperty(FormProperty.FORM_FIELD_LABEL);
SelectFieldItem item = new SelectFieldItem(label, blockElement);
selectElement.addOption(item);

Boolean isFlattenFromProperty = selectElement.<Boolean>getProperty(FormProperty.FORM_FIELD_FLATTEN);
if (childTagWorker instanceof OptGroupTagWorker && !Boolean.TRUE.equals(isFlattenFromProperty)) {
LOGGER.warn(Html2PdfLogMessageConstant.OPTGROUP_NOT_SUPPORTED_IN_INTERACTIVE_SELECT);
}

return true;
}
}
Expand Down
Loading

0 comments on commit 353b122

Please sign in to comment.