Release iText 7.1.11
iText 7.1.11 brings the second quarterly release of 2020 for the iText 7 family, with SEVEN (7) out of EIGHT product releases. You know what? We could even round that off, as the only product that we're not releasing, pdfSweep, also benefits from changes to Core.
Included is some pretty cool stuff (even a new icon for RUPS!), though we are particularly excited about the brand new version 3.0 of iText pdfHTML (check out the Release notes for that).
Breaking Changes
License Key
Our licensing mechanism (iText License Key Library & iText License Key Library Volume), will now require for "Volume Subscription" license holders, that the reporting will either have to be remote (our most convenient way for usage reporting) or local. This should make reporting your usage much easier and more flexible. If nothing is specified, remote will be the default. For more information, please check our Volume FAQ.
iText pdfHTML
- the Ledger page size will now be portrait oriented by default (if you prefer landscape, you just need to specify it);
- the rendering of HTML as PDF files now has a closer behavior to how a web browser would render the content. If you would like to maintain the previous behavior with pdfHTML 3.x, then we've provided you with the following Java and C# code:
package com.itextpdf.samples.sandbox.pdfhtml;
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.attach.ITagWorker;
import com.itextpdf.html2pdf.attach.ProcessorContext;
import com.itextpdf.html2pdf.css.apply.ICssApplier;
import com.itextpdf.html2pdf.css.apply.ICssApplierFactory;
import com.itextpdf.html2pdf.css.apply.impl.BodyTagCssApplier;
import com.itextpdf.html2pdf.css.apply.impl.DefaultCssApplierFactory;
import com.itextpdf.html2pdf.html.TagConstants;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.layout.IPropertyContainer;
import com.itextpdf.layout.font.FontProvider;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.layout.properties.RenderingMode;
import com.itextpdf.styledxmlparser.node.IElementNode;
import com.itextpdf.styledxmlparser.node.IStylesContainer;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class PdfHtmlRenderingMode {
public static final String SRC = "./src/main/resources/pdfhtml/PdfHtmlRenderingMode/";
public static final String DEST = "./target/sandbox/pdfhtml/PdfHtmlRenderingMode.pdf";
public static void main(String[] args) throws IOException {
String currentSrc = SRC + "PdfHtmlRenderingMode.html";
File file = new File(DEST);
file.getParentFile().mkdirs();
new PdfHtmlRenderingMode().manipulatePdf(currentSrc, DEST, SRC);
}
public void manipulatePdf(String htmlSource, String pdfDest, String freeFontsDirectory) throws IOException {
// In pdfHTML the iText layouting mechanism now works in HTML rendering mode. In order
// to switch to the iText default rendering mode, you should declare a custom ICssApplierFactory
// in which to create a custom ICssApplier for the body node. Then set the default rendering mode
// property for the property container.
ICssApplierFactory customCssApplierFactory = new DefaultModeCssApplierFactory();
// Starting from pdfHTML version 3.0.0 the GNU Free Fonts family (e.g. FreeSans) that were shipped together with the pdfHTML distribution
// are now replaced by Noto fonts. If your HTML file contains characters which are not supported by standard PDF fonts (basically most of the
// characters except latin script and some of the symbol characters, e.g. cyrillic characters like in this sample) and also if no other fonts
// are specified explicitly by means of iText `FontProvider` class or CSS `@font-face` rule, then pdfHTML shipped fonts covering a wide range
// of glyphs are used instead. In order to replicate old behavior, one needs to exclude from `FontProvider` the fonts shipped by default and
// provide GNU Free Fonts instead. GNU Free Fonts can be found at https://www.gnu.org/software/freefont/.
FontProvider fontProvider = new DefaultFontProvider(true, false, false);
fontProvider.addDirectory(freeFontsDirectory);
ConverterProperties converterProperties = new ConverterProperties()
.setBaseUri(freeFontsDirectory)
// Try removing registering of custom DefaultModeCssApplierFactory to compare legacy behavior
// with the newly introduced. You would notice that now lines spacing algorithm is changed:
// line spacing is considerably smaller and is closer compared to browsers rendering.
// You would also notice that now single image in a line behaves according to HTML's "noQuirks" mode:
// there's an additional "spacing" underneath the image which depends on element's `line-height` and
// `font-size` CSS properties.
.setCssApplierFactory(customCssApplierFactory)
.setFontProvider(fontProvider);
// When converting using the method #convertToElements to change the rendering mode you must also
// use the flag Property.RENDERING_MODE. However it must be added to the elements from the
// resulting list before adding these elements to the document. Then the elements will be
// placed in the specified mode.
HtmlConverter.convertToPdf(new FileInputStream(htmlSource), new FileOutputStream(pdfDest), converterProperties);
}
private static class DefaultModeCssApplierFactory extends DefaultCssApplierFactory {
@Override
public ICssApplier getCustomCssApplier(IElementNode tag) {
if (TagConstants.BODY.equals(tag.name())) {
return new DefaultModeBodyTagCssApplier();
}
return null;
}
}
private static class DefaultModeBodyTagCssApplier extends BodyTagCssApplier {
@Override
public void apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker) {
super.apply(context, stylesContainer, tagWorker);
IPropertyContainer container = tagWorker.getElementResult();
// Enable default mode
container.setProperty(Property.RENDERING_MODE, RenderingMode.DEFAULT_LAYOUT_MODE);
}
}
}
using System;
using System.IO;
using iText.Html2pdf;
using iText.Html2pdf.Attach;
using iText.Html2pdf.Css.Apply;
using iText.Html2pdf.Css.Apply.Impl;
using iText.Html2pdf.Html;
using iText.Html2pdf.Resolver.Font;
using iText.Layout;
using iText.Layout.Font;
using iText.Layout.Properties;
using iText.StyledXmlParser.Node;
namespace iText.Samples.Sandbox.Pdfhtml
{
public class PdfHtmlRenderingMode
{
public static readonly String SRC = "../../../resources/pdfhtml/PdfHtmlRenderingMode/";
public static readonly String DEST = "results/sandbox/pdfhtml/PdfHtmlRenderingMode.pdf";
public static void Main(string[] args)
{
String currentSrc = SRC + "PdfHtmlRenderingMode.html";
FileInfo file = new FileInfo(DEST);
file.Directory.Create();
new PdfHtmlRenderingMode().ManipulatePdf(currentSrc, DEST, SRC);
}
public void ManipulatePdf(String htmlSource, String pdfDest, String freeFontsDirectory)
{
// In pdfHTML the iText layouting mechanism now works in HTML rendering mode. In order
// to switch to the iText default rendering mode, you should declare a custom ICssApplierFactory
// in which to create a custom ICssApplier for the body node. Then set the default rendering mode
// property for the property container.
ICssApplierFactory customCssApplierFactory = new DefaultModeCssApplierFactory();
// Starting from pdfHTML version 3.0.0 the GNU Free Fonts family (e.g. FreeSans) that were shipped together with the pdfHTML distribution
// are now replaced by Noto fonts. If your HTML file contains characters which are not supported by standard PDF fonts (basically most of the
// characters except latin script and some of the symbol characters, e.g. cyrillic characters like in this sample) and also if no other fonts
// are specified explicitly by means of iText `FontProvider` class or CSS `@font-face` rule, then pdfHTML shipped fonts covering a wide range
// of glyphs are used instead. In order to replicate old behavior, one needs to exclude from `FontProvider` the fonts shipped by default and
// provide GNU Free Fonts instead. GNU Free Fonts can be found at https://www.gnu.org/software/freefont/.
FontProvider fontProvider = new DefaultFontProvider(true, false, false);
fontProvider.AddDirectory(freeFontsDirectory);
ConverterProperties converterProperties = new ConverterProperties()
.SetBaseUri(freeFontsDirectory)
// Try removing registering of custom DefaultModeCssApplierFactory to compare legacy behavior
// with the newly introduced. You would notice that now lines spacing algorithm is changed:
// line spacing is considerably smaller and is closer compared to browsers rendering.
// You would also notice that now single image in a line behaves according to HTML's "noQuirks" mode:
// there's an additional "spacing" underneath the image which depends on element's `line-height` and
// `font-size` CSS properties.
.SetCssApplierFactory(customCssApplierFactory)
.SetFontProvider(fontProvider);
// When converting using the method #convertToElements to change the rendering mode you must also
// use the flag Property.RENDERING_MODE. However it must be added to the elements from the
// resulting list before adding these elements to the document. Then the elements will be
// placed in the specified mode.
HtmlConverter.ConvertToPdf(new FileStream(htmlSource, FileMode.Open, FileAccess.Read),
new FileStream(pdfDest, FileMode.Create), converterProperties);
}
private class DefaultModeCssApplierFactory : DefaultCssApplierFactory
{
public override ICssApplier GetCustomCssApplier(IElementNode tag)
{
if (TagConstants.BODY.Equals(tag.Name()))
{
return new DefaultModeBodyTagCssApplier();
}
return null;
}
}
private class DefaultModeBodyTagCssApplier : BodyTagCssApplier
{
public override void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker)
{
base.Apply(context, stylesContainer, tagWorker);
IPropertyContainer container = tagWorker.GetElementResult();
// Enable default mode
container.SetProperty(Property.RENDERING_MODE, RenderingMode.DEFAULT_LAYOUT_MODE);
}
}
}
}
Release Related Examples
GitHub | Maven | NuGet | Artifactory | |
---|---|---|---|---|
iText 7 Core – 7.1.11 (Java) | link | link | N/A | link |
iText 7 Core – 7.1.11 (.NET) | link | N/A | link | link |
iText License Key Library – 3.1.0 | N/A | link | link | link |
iText License Key Library Volume – 3.1.0 | N/A | link | link | link |
iText pdf2Data – 2.1.7 (Java) | N/A | N/A | N/A | link |
iText pdf2Data – 2.1.7 (.NET) | N/A | N/A | link | link |
iText pdfCalligraph – 2.0.6 (Java) | N/A | link | N/A | link |
iText pdfCalligraph – 2.0.6 (.NET) | N/A | N/A | link | link |
iText pdfHTML – 3.0.0 (Java) | link | link | N/A | link |
iText pdfHTML – 3.0.0 (.NET) | link | N/A | link | link |
iText pdfRender – 1.0.1 (Java) | N/A | link | N/A | link (CLI) |
iText pdfXFA – 2.0.6 (Java) | N/A | link | N/A | link |
iText pdfXFA – 2.0.6 (.NET) | N/A | N/A | link | link |
iText RUPS – 7.1.11 | link | link | N/A | link |
In alphabetical order, here's an overview of the changes that each product has with this quarterly release:
- A bug fix with XFDF as squares and circles could not be made optional;
- More robust PNG handling;
- Better handling of form fields (specifically when /TI value is present, and when using SetValue for a choice form field);
- Improved table splitting;
- Improve RegexBasedCleanupStrategy (Java/.NET) (although a Core change, it benefits iText pdfSweep) when white spaces are available (thank you vemoo for the PR (#1 and #2)!);
- Added control over widow/orphan content (we have an example for Java and .NET (C#) on this new functionality).
- More stable data extraction in cases of non-critical errors in PDF syntax.
- Better Arabic (fix in Tanween characters rendering, and some characters that were being truncated at the end);
- Improved Khmer script rendering.
- Support for the line-height property for inline-level elements as well (in addition to improved support for block-level elements);
- Improve line height calculation differences between browsers and PDF rendering (this is a breaking change, check above for how to revert the behavior);
- Improve creation and/or merging of outlines;
- Support for widows and orphans properties.
- We now have a CLI (Command Line Interface) wrapper around pdfRender, so you can use it outside of a Java only environment.
- New icon!
- Better handling of lists in rich text fields;
- Better support for <draw>, <float> and <subformSet> tags.
Also, a couple of points related to our licensing and volume counting mechanisms:
- Expiration checks are now locale-independent (this is relevant if you are using a Trial license, or have an expiration date on your commercial license);
- As referred on the Breaking Changes, if you have a "Volume Subscription License", you will have to specify if you want to do your volume counting locally, or remote. You can check our Volume Counter FAQs for further details.
New Features
- [CORE] Improve creation and(or) merging of outlines for documents created in pdfHTML
- [CORE & PDFHTML] Basic implementation of orphan/widow control
- [LICENSE] Implement EventDataHandler for stable local volume counting files writing and rotating
- [LICENSE] Implement user-side configuration of volume counting library mode (public API, ENV and license file)
- [LICENSE] Fail license check for volume license in AWS mode if AWS is not available on startup
- [LICENSE] Enable local volume counting file mode
- [PDFHTML] Added support for the Line height property
- [PDFRENDER] Introduce CLI to simplify usage from non-Java environments
Improvements
- [CORE] itext7-dotnet PR #6 (and i7n-pdfsweep PR #1): Fix missing index and newlines in cleanup regexes (thank you vemoo!)
- [CORE] itext7 PR #44: Fix null pointer in PdfAcroForm (thank you craftmaster2190!)
- [CORE] itext7-dotnet PR #4: Path transformation to userspace (thank you Moneema14 for the inspiration!)
- [CORE] While checking whether a cell with a fixed height should be split, float are compared without any epsilon value, which may cause issues because of float precision inaccuracy
- [PDFHTML] Get rid of the difference in line height calculations between HTML and PDF
- [PDFRENDER] Improve log and exception messages
- [RUPS] Update logo
Bugs
- [CORE] Make fringe attribute in xfdf squre and circle annotations optional
- [CORE] Several bugs in processing of /TI for choice fields
- [CORE] setValue method works incorrectly for a choice form field
- [CORE] NotoSerifKhmer is rendered poorly
- [CORE] GposLookupType5: mark to ligature positioning results in duplicating the mark
- [CORE] Fix issue with Khmer text being incorrectly formatted
- [CORE] Adding a PNG to pdf creates unopenable pdf document
- [CORE] The FillOpacity is not set correctly on the GraphicsState of TextRenderInfo
- [LICENSE] Ensure licensekey expiration checks are locale-independent (Thai Buddhist calendar, Arabic calendar)
- [PDFCALLIGRAPH] New glyphs which have been added while applying positioning features do not affect the start/end of the appropriate glyphline
- [PDFCALLIGRAPH] Arabic: glyph is truncated
- [PDFCALLIGRAPH] iText printing two arabic Tanween characters( Ù‹ ) instead of one
- [PDFRENDER] pdfRender fails to correctly render PDF files encrypted with AES256
- [PDFRENDER] pdfRender fails to process text in Myriad Pro
- [PDFRENDER] pdfRender jar contains unnecessary dependencies (layout, forms, licensekey,...)
- [PDFXFA] <float> tag value from FormState is not applied to a field
- [PDFXFA] Form state is not applied for <draw> elements
- [PDFXFA] Subforms are unexpectedly multiplied because default relation of subformSet is not respected
- [PDFXFA] Fix difference between Java and .NET version of XFAWorker/pdfXFA for particular template flattening
- [PDFXFA] Flattening TextFields with rich text in them with nested lists is poorly handled