New in PD4ML v4.1.0


In version PD4ML v4.1.0 the product has been improved in the following areas:

  • Security – AES-128 is used as the default encryption method
     
  • PDF Standards conformance – allows you to specify the required PDF standard compliance. See: Compliance with PDF standards
     
  • XML invoicing support – simplifies the creation of XML invoices that comply with the hybrid electronic invoicing standards. See: ZUGFeRD and Factur-X PDF Invoices generation
     
  • Error policies – You can now specify how errors are handled: either ignore them or throw an exception at the caller level. Four policies can be defined: RELAXED (default; ignore all errors where possible), NORMAL (throw an exception on error), PEDANTIC (treat potential PDF/A and PDF/UA incompatibility as an error and throw an exception), and STRICT (throw an exception even on warnings, such as if the specified font cannot display some text and a fallback font is required).
     

Compliance with PDF standards


PD4ML v4.1.0 introduces a new API method, pd4ml.writePDF(OutputStream, PdfSpec), which allows you to specify the required PDF standard compliance level.

Available options:

  • PDF1.4PdfSpec.PDF_1_4 – Acrobat 5
  • PDF1.5PdfSpec.PDF_1_5 – Acrobat 6
  • PDF1.6PdfSpec.PDF_1_6 – Acrobat 7
  • PDF1.7PdfSpec.PDF_1_7 – Acrobat 8 / ISO 3200-1
  • PDF1.7ext1PdfSpec.PDF_1_7_1
  • PDF1.7ext2PdfSpec.PDF_1_7_2
  • PDF1.7ext3PdfSpec.PDF_1_7_3 – Acrobat 9
  • PDF1.7ext4PdfSpec.PDF_1_7_4
  • PDF1.7ext5PdfSpec.PDF_1_7_5
  • PDF1.7ext6PdfSpec.PDF_1_7_6
  • PDF1.7ext7PdfSpec.PDF_1_7_7
  • PDF1.7ext8PdfSpec.PDF_1_7_8 – Acrobat X
  • PDF1.7ext9PdfSpec.PDF_1_7_9
  • PDF1.7ext10PdfSpec.PDF_1_7_10
  • PDF1.7ext11PdfSpec.PDF_1_7_11 – Acrobat XI
  • PDF2.0PdfSpec.PDF_2_0

The PdfSpec parameter can be combined with one of PDF/A modifiers

  • PDF/A-1a:2005PdfSpec.PDFA_1A
  • PDF/A-1b:2005PdfSpec.PDFA_1B
  • PDF/A-2aPdfSpec.PDFA_2A
  • PDF/A-2bPdfSpec.PDFA_2B
  • PDF/A-2uPdfSpec.PDFA_2U
  • PDF/A-3aPdfSpec.PDFA_3A
  • PDF/A-3bPdfSpec.PDFA_3B
  • PDF/A-3uPdfSpec.PDFA_3U
  • PDF/A-4PdfSpec.PDFA_4 – requires PDF2.0
  • PDF/A-4ePdfSpec.PDFA_4E – requires PDF2.0

The combining can be done as follows:

    pd4ml.writePDF(os, PdfSpec.PDFA_3B); // implicitly adds PDF1.7 conformance
    pd4ml.writePDF(os, PdfSpec.PDF_1_7_8.combine(PdfSpec.PDFA_3B));

And also PDF or PDF/A-a can be combined with PDF/UA

  • PDF/UA-1PdfSpec.PDFUA_1
  • PDF/UA-2PdfSpec.PDFUA_2 – requires PDF2.0

Examples:

    pd4ml.writePDF(os, PdfSpec.PDFUA_1); // implicitly adds PDF1.7 conformance
    pd4ml.writePDF(os, PdfSpec.PDF_1_7_8.combine(PdfSpec.PDFUA_1));
    pd4ml.writePDF(os, PdfSpec.PDF_1_7_11.combine(PdfSpec.PDFA_3A).combine(PdfSpec.PDFUA_1));

There are also several predefined constants that combine PDF standards as required by XML invoicing specs:

  • ZUGFeRDPdfSpec.ZUGFeRD, which is PdfSpec.PDF_1_7.combine(PdfSpec.PDFA_3B)
  • ZUGFeRD (tagged)PdfSpec.ZUGFeRD_a, which is PdfSpec.PDF_1_7.combine(PdfSpec.PDFA_3A)
  • Factur-XPdfSpec.FacturX, which is PdfSpec.PDF_1_7.combine(PdfSpec.PDFA_3B)
  • Factur-X (tagged)PdfSpec.FacturX_a, which is PdfSpec.PDF_1_7.combine(PdfSpec.PDFA_3A)

 

NOTE: Not all the standards can be combined with each other. PdfSpec.combine() throws PdfSpecViolationException and PdfSpecUnsupportedException in incompatibility cases.

ZUGFeRD and Factur-X PDF Invoices generation support


Starting with version v4.1.0, PD4ML DMS and PD4ML UA support PDF/A-3b format and embedding XML invoices into PDF files.

Now, it’s possible to combine both the document’s visual human-readable presentation and its ZUGFeRD/Factur-X XML machine-readable data in a single HTML template. The HTML template can either be completely generated on the fly by the host applicaion, or a static pre-prepared template marked with placeholders can be populated with dynamic data using PD4ML.

Read more: ZUGFeRD and Factur-X PDF Invoices generation

Creating DOCX Files


v4.0.19 introduces support for creating OOXML (DOCX) files from HTML.

It is already functionally superior to the long-standing PD4ML HTML to RTF converter. It allows you to define text and paragraph styles, nested tables, ordered and unordered lists, headers and footers, table of contents, hyperlinks, bookmarks, borders, backgrounds, and embed images.

To force DOCX output you only need to trigger pd4ml.writeDOCX() API method instead of pd4ml.writePDF() in usual conversion scenarios.

The converter is available under the PD4ML DMS or PD4ML UA license.

Read more: https://pd4ml.com/creation-of-ooxml-docx-documents/

PD4ML Fonts Tool


To simplify the creation of font mapping files, PD4ML v4.0.16 introduces a handy tool. The tool is implemented as an utility of the interactive PD4ML Converter

How to use it

Run the converter, as described by the link /support-topics/pd4ml-v4-programmers-manual/ and click the [Fonts Tool] button on the status bar of the application window.

It will prompt you for the location of the font directory. Select a directory. We can start with system fonts like C:\Windows\Fonts

Because the system font directory contains an excessive number of fonts that your application doesn’t really need, you can filter them out by entering a comma-separated list of font name patterns in the input field next to the “Filter by Font File Name” button. Apply the filter by pressing the button. The resulting list will include only those fonts whose filenames case-insensitively match the given patterns.

The generated list is editable, so you can manually refine it.

At this point you have four options:

  • Close – is obvious: close the tool and lose the current font mapping configuration
  • Use – use the font configuration only in the current session of the PD4ML Converter, without saving it.
  • Save Mapping File – creates a pd4fonts.properties file that can later be referenced from your application with pd4ml.useTTF() API call. If the chosen mapping file location is different from the original font directory (which is a good idea if you are using the system font directory), pd4fonts.properties will include a link to the font dir, allowing PD4ML to find the actual font files.
  • Save as JAR – packages the listed fonts and the corresponding pd4fonts.properties into a JAR file. Fonts are stored in the “pdffonts” JAR subdirectory by default, so once the JAR is deployed with a PD4ML-enabled application, the font configuration can be referenced with pd4ml.useTTF("java:pdffonts") API call. The subdirectory name can be customized by uncommenting and setting the jar.folder=pdffonts property.

Apache Batik SVG plugin control


PD4ML implements its own basic SVG renderer, and also allows you to use third-party libraries for the task. If it finds Apache Batik SVG Toolkit among the available libraries, it will automatically switch to it.

Batik tries to implement most of the features of SVG. But, unfortunately, it is very sensitive to even minor file format errors, and there is no way to change its error policy: it always throws exceptions, and there is no switch to turn them into warnings, for example.

In such cases, the best workaround would be to disable Batik and let the built-in SVG engine do the rendering.

Java code to disable Batik:

com.pd4ml.plugins.BatikSvgCustomTag.disable = true;

Disable in pd4browser.properties:

svg.batik=false

CSS Flexible Box Layout support added


PD4ML v4.0.6 introduces flexbox layout support.

Children of a flex container can “flex” their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children is supported.

Automatic Font Kerning Support


PD4ML v4.0.4 introduces optional font kerning support. Kerning is an addition or reduction of space between two characters (glyphs) of a proportional font. As a rule a rendered text is visually much more pleasing when the kerning is applied.

PD4ML uses kerning pairs info from TTF/OTF fonts (if available). For the standard built-in Type1 fonts the kerning info is known and included to PD4ML product itself.

The feature is also implemented in our older development branch v3.11.0 due to its importance

Creating high quality accessible PDF/UA documents


One of the major reasons to migrate to PD4ML v4 API is the support of the PDF/UA standard (Universal Accessibility).

PDF/UA standard is to let people with disabilities access PDF information in an efficient manner without assistance from others and be able to receive the same value from the content as others. PDF/UA does not add any new features to the PDF file format, but makes some aspects required which are optional in a regular PDF.

A lot of the requirements, like fonts embedding, were implicitly fulfilled even by older versions of PD4ML. But the major ones are covered only starting from PD4ML v4 – thanks to the new product architecture, which has been designed bearing in mind PDF/UA conformance.

PDF/UA requirements
  • PDF/UA document must be tagged. It must include information regarding the nesting and relationship of different types of structure elements. It is probably the most annoying task to fulfill if you create PDF/UA using WYSIWYG tools from scratch or do manual PDF post-processing to achieve PDF/UA conformance. With PD4ML the task is trivial: a document structure comes from input HTML and can be perfectly automatically transformed to PDF tags.
  • The document structure elements must have alternative descriptions. PD4ML uses for that a content specified by TITLE and ALT attributes of HTML tags. It is also a good idea to specify LANG attribute if the content not in English.
  • PDF/UA document must be supplied with XML metadata. PD4ML generates it for you from known document/environment info. Make sure your input HTML document specifies <title>, <meta name="description" content="document subject">, <meta name="author" content="author name">, <meta name="keywords" content="comma-delimited list of keywords"> etc.
Enabling PDF/UA output

First you need to obtain PD4ML UA license with a license code. See the documentation.

Without the license code (or with a code of PD4ML license type, which does not enable PDF/UA feature) it still going to generate PDF/UA documents, but watermarked with “Evaluation” banner.

The next step is straightforward: invoke writePDF() method with PDFUA parameter.

PD4ML pd4ml = new PD4ML();

// important! PDF/UA requires TTF fonts to be embedded
// "arial,times,courier" is a comma-delimited list of font file name patterns to use
pd4ml.useTTF("c:/Windows/Fonts/", "arial,times,courier");

String html = "<html>\n" + 
		"<head>\n" + 
		"<title>PDF/UA Test</title>\n" + 
		"<meta name=\"description\" content=\"Document Subject\" />\n" + 
		"<meta name=\"author\" content=\"Max Mustermann\" />\n" + 
		"</head>\n" + 
		"<body lang=\"DE-de\">\n" + 
		"<div title=\"PDF/UA test content\">Prüfung auf PDF/UA-Konformität</div>\n" + 
		"</body>\n" + 
		"</html>";

ByteArrayInputStream bais =
        new ByteArrayInputStream(html.getBytes());

// read and parse HTML
pd4ml.readHTML(bais);

File pdf = File.createTempFile("result", ".pdf");
FileOutputStream fos = new FileOutputStream(pdf);

// render and write the result as PDF
pd4ml.writePDF(fos, Constants.PDFUA);

// open the just-generated PDF with a default PDF viewer
Desktop.getDesktop().open(pdf);

If you run PD4ML as a standalone command line tool, you may force it to output PDF/UA with -outformat pdfua parameter.

In both cases do not forget to point PD4ML to a folder with indexed TTF/OTF fonts using pd4ml.useTTF(fontDir) API call or -ttf <ttf_fonts_dir> command line parameter.

PDF/UA validation

After PDF document is generated, it is a good idea to validate it for PDF/UA conformity. PD4ML did the best, but there are some aspects, that cannot be fully automated (e.g. providing of alternative descriptions).

There is a variety of PDF and PDF/UA validator tools. Our choice is free Free PDF Accessibility Checker (PAC 3)

The PAC3 tool creates detailed validation reports, allows to browse the document structure to the problem elements and highlight them in the rendered content. However error messages can be not always clear. With some practice and collected validation experience their meaning becomes less confusing.

Alternatively you may use Preflight included to Adobe Acrobat Pro or diverse online validator applications (e.g. 3-HEIGHTS™ PDF VALIDATOR ONLINE TOOL). The tools are also great, but comparing to PAC3, they are mostly focused not on accessibility issues, but on technical/syntax aspects of PDF code (which should be not your, but our concern).

Most typical validation errors
  1. Despite the message, the real validation error reason is a missing of <thead> section in a table. Add missing <thead> section to suppress the message. PD4ML creates an implicit <thead> section if leading table rows contain <th> cells only.
  2. The message is clear: in PDF/UA you are not allowed to nest, let’s say, <h4> heading to <h2>, which happens quite often in real life HTML documents.