Skip to content

Commit

Permalink
[RELEASE] iText pdfHtml 5.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
iText-CI committed Oct 17, 2023
2 parents 353b122 + d0c13e2 commit f96f0f1
Show file tree
Hide file tree
Showing 192 changed files with 9,908 additions and 177 deletions.
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to iText 7 Community
# Contributing to iText Community

We'd love for you to contribute to our source code and to make **iText 7 Community** even better than it is
We'd love for you to contribute to our source code and to make **iText Community** even better than it is
today! Here are the guidelines we'd like you to follow:

- [Question or Problem?](#question)
Expand All @@ -15,7 +15,7 @@ today! Here are the guidelines we'd like you to follow:

## <a name="question">Got a Question or Problem?</a>

If you have questions about how to use **iText 7 Community**, please direct these to [Stack Overflow][stackoverflow].
If you have questions about how to use **iText Community**, please direct these to [Stack Overflow][stackoverflow].

If you are a customer with a [support agreement][support], you also have direct access to our JIRA and our developers.

Expand Down Expand Up @@ -55,7 +55,7 @@ chances of your issue being dealt with quickly:
* **Related Issues** - has a similar issue been reported before?
* **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
causing the problem (line of code or commit)
* **Tag the question** - add the tag `itext7` to your question so we can find it.
* **Tag the question** - add the tag `itext` to your question so we can find it.

**If you get help, help others. Good karma rulez!**

Expand All @@ -79,7 +79,7 @@ Before you submit your pull request consider the following guidelines:
* Build your changes locally to ensure all the tests pass.
* Push your changes to your GitHub account.
* Create a pull request in GitHub.
"Head fork" should be your repository, and the "base fork" should be the iText7 official repository.
"Head fork" should be your repository, and the "base fork" should be the iText official repository.
* If we suggest changes then:
* Make the required updates.
* Fix up your commits if needed, with an interactive rebase.
Expand Down Expand Up @@ -111,7 +111,7 @@ To ensure consistency throughout the source code, keep these rules in mind as yo

We have guidelines on how our git commit messages should be formatted. This leads to **more
readable messages** that are easy to follow when looking through the **project history**. But also,
we use the git commit messages to **generate the iText 7 Community change log**.
we use the git commit messages to **generate the iText Community change log**.

These guidelines were taken from Chris Beams' blog post [How to Write a Git Commit Message][git-commit].

Expand Down Expand Up @@ -169,7 +169,7 @@ We use the [Stack Exchange][stackoverflow] network for free support and [GitHub]
[javadocs]: https://itextpdf.com/api
[pull]: https://github.com/itext/i7j-pdfhtml/pulls
[sscce]: http://sscce.org/
[stackoverflow]: https://stackoverflow.com/questions/tagged/itext7
[stackoverflow]: https://stackoverflow.com/questions/tagged/itext
[good-questions]: https://stackoverflow.com/help/how-to-ask
[mcve]: https://stackoverflow.com/help/mcve
[support]: https://itextpdf.com/support
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**[pdfHtml][pdfHtml]** is an [iText 7][itext] add on.
**[pdfHtml][pdfHtml]** is an [iText][itext] add on.

This add on will allow you to easily convert HTML to PDF or iText objects.

Expand Down Expand Up @@ -35,4 +35,4 @@ Contact [sales] for more info.
[latest]: https://github.com/itext/i7j-pdfhtml/releases/latest
[sales]: http://itextpdf.com/sales
[gratis]: https://en.wikipedia.org/wiki/Gratis_versus_libre
[pdfHtml]: http://itextpdf.com/itext7/pdfHtml
[pdfHtml]: https://itextpdf.com/products/convert-html-css-to-pdf-pdfhtml
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>8.0.1</version>
<version>8.0.2</version>
<relativePath />
</parent>

<artifactId>html2pdf</artifactId>
<version>5.0.1</version>
<version>5.0.2</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
them to PDF.</description>

<scm>
<connection>scm:git:ssh://[email protected].com:7999/i7j/html2pdf.git</connection>
<url>https://git.itextsupport.com/projects/I7J/repos/html2pdf</url>
<connection>git@github.com:itext/i7j-pdfhtml.git</connection>
<url>https://github.com/itext/i7j-pdfhtml</url>
</scm>

<properties>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/itextpdf/html2pdf/ConverterProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ This file is part of the iText (R) project.
*/
package com.itextpdf.html2pdf;

import com.itextpdf.commons.actions.contexts.IMetaInfo;
import com.itextpdf.html2pdf.attach.ITagWorkerFactory;
import com.itextpdf.html2pdf.attach.impl.OutlineHandler;
import com.itextpdf.html2pdf.css.apply.ICssApplierFactory;
import com.itextpdf.commons.actions.contexts.IMetaInfo;
import com.itextpdf.layout.font.FontProvider;
import com.itextpdf.styledxmlparser.css.media.MediaDeviceDescription;
import com.itextpdf.styledxmlparser.resolver.resource.IResourceRetriever;
Expand Down Expand Up @@ -326,8 +326,11 @@ public boolean isCreateAcroForm() {
* If createAcroForm is set, then when the form is encountered in HTML, AcroForm will be created, otherwise
* a visually identical, but not functional element will be created. Please bare in mind that the created
* Acroform may visually differ a bit from the HTML one.
* <p>
* When enabling this acroform creation, it will disable the immediateFlushing property.
*
* @param createAcroForm true if an AcroForm needs to be created
*
* @return the {@link ConverterProperties} instance
*/
public ConverterProperties setCreateAcroForm(boolean createAcroForm) {
Expand Down
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.1";
private static final String PDF_HTML_VERSION = "5.0.2";
private static final int PDF_HTML_COPYRIGHT_SINCE = 2000;
private static final int PDF_HTML_COPYRIGHT_TO = 2023;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This file is part of the iText (R) project.
import com.itextpdf.html2pdf.attach.util.WaitingInlineElementsHelper;
import com.itextpdf.html2pdf.css.CssConstants;
import com.itextpdf.html2pdf.html.AttributeConstants;
import com.itextpdf.html2pdf.logs.Html2PdfLogMessageConstant;
import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfString;
Expand All @@ -45,15 +46,24 @@ This file is part of the iText (R) project.
import com.itextpdf.styledxmlparser.node.IElementNode;
import com.itextpdf.styledxmlparser.node.INode;

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

/**
* TagWorker class for the {@code html} element.
*/
public class HtmlTagWorker implements ITagWorker {

/** The iText document instance. */
private static final Logger LOGGER = LoggerFactory.getLogger(HtmlTagWorker.class);

/**
* The iText document instance.
*/
private Document document;

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

/**
Expand All @@ -65,14 +75,19 @@ public class HtmlTagWorker implements ITagWorker {
public HtmlTagWorker(IElementNode element, ProcessorContext context) {
// TODO DEVSIX-4261 more precise check if a counter was actually added to the document
boolean immediateFlush =
context.isImmediateFlush() && !context.getCssContext().isPagesCounterPresent();
context.isImmediateFlush() && !context.getCssContext().isPagesCounterPresent()
&& !context.isCreateAcroForm();
if (context.isImmediateFlush() && context.isCreateAcroForm()) {
LOGGER.info(Html2PdfLogMessageConstant.IMMEDIATE_FLUSH_DISABLED);
}
PdfDocument pdfDocument = context.getPdfDocument();
document = new HtmlDocument(pdfDocument, pdfDocument.getDefaultPageSize(), immediateFlush);
document.setRenderer(new HtmlDocumentRenderer(document, immediateFlush));

DefaultHtmlProcessor.setConvertedRootElementProperties(element.getStyles(), context, document);

inlineHelper = new WaitingInlineElementsHelper(element.getStyles().get(CssConstants.WHITE_SPACE), element.getStyles().get(CssConstants.TEXT_TRANSFORM));
inlineHelper = new WaitingInlineElementsHelper(element.getStyles().get(CssConstants.WHITE_SPACE),
element.getStyles().get(CssConstants.TEXT_TRANSFORM));

String lang = element.getAttribute(AttributeConstants.LANG);
if (lang != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ This file is part of the iText (R) project.
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.properties.ObjectFit;
import com.itextpdf.styledxmlparser.node.IElementNode;
import com.itextpdf.svg.element.SvgImage;
import com.itextpdf.svg.xobject.SvgImageXObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -71,6 +73,8 @@ public ImgTagWorker(IElementNode element, ProcessorContext context) {
if (imageXObject != null) {
if (imageXObject instanceof PdfImageXObject) {
image = new HtmlImage((PdfImageXObject) imageXObject);
} else if (imageXObject instanceof SvgImageXObject) {
image = new SvgImage((SvgImageXObject) imageXObject);
} else if (imageXObject instanceof PdfFormXObject) {
image = new HtmlImage((PdfFormXObject) imageXObject);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ This file is part of the iText (R) project.
import com.itextpdf.html2pdf.util.SvgProcessingUtil;
import com.itextpdf.commons.utils.FileUtil;
import com.itextpdf.commons.utils.MessageFormatUtil;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.layout.IPropertyContainer;
import com.itextpdf.layout.element.Image;
import com.itextpdf.styledxmlparser.node.IElementNode;
Expand Down Expand Up @@ -117,17 +116,10 @@ private boolean isSvgImage(String typeAttribute) {

@Override
public void processEnd(IElementNode element, ProcessorContext context) {
if (context.getPdfDocument() != null) {
PdfDocument document = context.getPdfDocument();
//Create Image object

if (res != null) {
image = processUtil.createImageFromProcessingResult(res, document);
AccessiblePropHelper.trySetLangAttribute(image, element);
}

} else {
LOGGER.error(Html2PdfLogMessageConstant.PDF_DOCUMENT_NOT_PRESENT);
// Create Image object
if (res != null) {
image = processUtil.createSvgImageFromProcessingResult(res);
AccessiblePropHelper.trySetLangAttribute(image, element);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public SvgTagWorker(IElementNode element, ProcessorContext context) {

@Override
public void processEnd(IElementNode element, ProcessorContext context) {
if (context.getPdfDocument() != null && processingResult != null) {
if (processingResult != null) {
SvgProcessingUtil util = new SvgProcessingUtil(context.getResourceResolver());
svgImage = util.createImageFromProcessingResult(processingResult, context.getPdfDocument());
svgImage = util.createSvgImageFromProcessingResult(processingResult);

AccessiblePropHelper.trySetLangAttribute(svgImage, element);
context.endProcessingInlineSvg();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ This file is part of the iText (R) project.
import com.itextpdf.html2pdf.attach.ProcessorContext;
import com.itextpdf.html2pdf.css.CssConstants;
import com.itextpdf.commons.utils.MessageFormatUtil;
import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.colors.gradients.StrategyBasedLinearGradientBuilder;
import com.itextpdf.kernel.pdf.xobject.PdfFormXObject;
import com.itextpdf.kernel.pdf.xobject.PdfImageXObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ This file is part of the iText (R) project.
import com.itextpdf.styledxmlparser.node.IElementNode;
import com.itextpdf.styledxmlparser.node.IStylesContainer;

import com.itextpdf.svg.element.SvgImage;
import com.itextpdf.svg.xobject.SvgImageXObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -145,6 +147,8 @@ public static void applyListStyleImageProperty(Map<String, String> cssProps, Pro
Image image = null;
if (imageXObject instanceof PdfImageXObject) {
image = new Image((PdfImageXObject) imageXObject);
} else if (imageXObject instanceof SvgImageXObject) {
image = new SvgImage((SvgImageXObject) imageXObject);
} else if (imageXObject instanceof PdfFormXObject) {
image = new Image((PdfFormXObject) imageXObject);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static void applyVerticalAlignmentForInlines(Map<String, String> cssProps
String vAlignVal = cssProps.get(CssConstants.VERTICAL_ALIGN);
if (vAlignVal != null) {

// TODO DEVSIX-1750 for inline images and tables (inline-blocks) v-align is not supported
// TODO DEVSIX-1961 for inline images and tables (inline-blocks) v-align is not supported

float textRise = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public final class Html2PdfLogMessageConstant {
public static final String PAGE_SIZE_VALUE_IS_INVALID = "Page size value {0} is invalid.";

/** The Constant PDF_DOCUMENT_NOT_PRESENT. */
@Deprecated
public static final String PDF_DOCUMENT_NOT_PRESENT = "PdfDocument is not present";

/** The Constant QUOTES_PROPERTY_INVALID. */
Expand Down Expand Up @@ -171,6 +172,7 @@ public final class Html2PdfLogMessageConstant {
public static final String ELEMENT_DOES_NOT_FIT_CURRENT_AREA = "Element does not fit current area";
public static final String OPTGROUP_NOT_SUPPORTED_IN_INTERACTIVE_SELECT = "Option groups are not supported in "
+ "interactive mode";
public static final String IMMEDIATE_FLUSH_DISABLED = "Setting createAcroForm disables immediateFlush property";

private Html2PdfLogMessageConstant() {
//Private constructor will prevent the instantiation of this class directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This file is part of the iText (R) project.

/**
* The default {@link BasicFontProvider} for pdfHTML, that, as opposed to
* the font provider in iText 7's styled-xml-parser, also includes a
* the font provider in iText's styled-xml-parser, also includes a
* series of fonts that are shipped with the add-on.
*/
public class DefaultFontProvider extends BasicFontProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ This file is part of the iText (R) project.
import com.itextpdf.styledxmlparser.resolver.resource.IResourceRetriever;
import com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver;
import com.itextpdf.svg.converter.SvgConverter;
import com.itextpdf.svg.element.SvgImage;
import com.itextpdf.svg.processors.ISvgProcessorResult;
import com.itextpdf.svg.processors.impl.SvgConverterProperties;

Expand All @@ -49,7 +50,7 @@ public class HtmlResourceResolver extends ResourceResolver {
private static final String SVG_PREFIX = "data:image/svg+xml";
private static final Pattern SVG_IDENTIFIER_PATTERN = Pattern.compile(",[\\s]*(<svg )");

private ProcessorContext context;
private final ProcessorContext context;

/**
* Creates a new {@link HtmlResourceResolver} instance.
Expand Down Expand Up @@ -108,7 +109,7 @@ protected PdfXObject tryResolveBase64ImageSource(String src) {
if (fixedSrc.startsWith(SVG_PREFIX)) {
fixedSrc = fixedSrc.substring(fixedSrc.indexOf(BASE64_IDENTIFIER) + BASE64_IDENTIFIER.length() + 1);
try (ByteArrayInputStream stream = new ByteArrayInputStream(Base64.decode(fixedSrc))) {
PdfFormXObject xObject = processAsSvg(stream, context, null);
PdfFormXObject xObject = HtmlResourceResolver.processAsSvg(stream, context, null);
if (xObject != null) {
return xObject;
}
Expand All @@ -131,7 +132,7 @@ protected PdfXObject createImageByUrl(URL url) throws Exception {

private PdfXObject tryResolveSvgImageSource(String src) {
try (ByteArrayInputStream stream = new ByteArrayInputStream(src.getBytes(StandardCharsets.UTF_8))) {
PdfFormXObject xObject = processAsSvg(stream, context, null);
PdfFormXObject xObject = HtmlResourceResolver.processAsSvg(stream, context, null);
if (xObject != null) {
return xObject;
}
Expand All @@ -147,11 +148,7 @@ private static PdfFormXObject processAsSvg(InputStream stream, ProcessorContext
svgConverterProperties.setBaseUri(parentDir);
}
ISvgProcessorResult res = SvgConverter.parseAndProcess(stream, svgConverterProperties);
if (context.getPdfDocument() != null) {
SvgProcessingUtil processingUtil = new SvgProcessingUtil(context.getResourceResolver());
return processingUtil.createXObjectFromProcessingResult(res, context.getPdfDocument());
} else {
return null;
}
SvgProcessingUtil processingUtil = new SvgProcessingUtil(context.getResourceResolver());
return processingUtil.createXObjectFromProcessingResult(res, context.getPdfDocument());
}
}
Loading

0 comments on commit f96f0f1

Please sign in to comment.