NEW IN PD4ML 4.2 · THE V42 ENGINE

Modern HTML and CSS, laid out the way Chrome prints it.

PD4ML 4.2 adds a second layout engine, v42, alongside the proven v40 engine. It parses HTML5 the way browsers do, lays out Flexbox, Grid and multi-column content, and is checked against Chrome's print output, with no headless browser, no native code and no external service.

Turn it on with one call: useHtmlRenderer(Constants.LayoutEngine.v42). Applications that don't opt in keep their v40 output unchanged.

Engine
v42, opt-in per conversion
Reference
Chrome's print output
Runtime
Pure Java, one JAR
Output
PDF, DOCX, RTF, Markdown, images
Status
v4.2.0 development snapshot
Flexbox
and CSS Grid
Multi-column
continued across pages
@page
with 16 margin boxes
Media queries 4
print and screen
DOM API
query, edit, measure
THE ENGINE

Your existing web skills, now on paper.

Templates built with current HTML and CSS convert as they are, so you don't have to rebuild them with tables and floats for the PDF.

A tolerant HTML5 parser

Broken or sloppy markup is repaired the way browsers repair it, so real-world HTML from editors, CMSs and e-mail converts without clean-up.

v4.2v42 engine

Flexbox and CSS Grid

Cards, sidebars, dashboards and invoice layouts use the CSS layout models your front-end team already knows. The v40 engine got better Flexbox too: order, flex-basis: 0%, align-self: stretch and browser-like margins.

v4.2v4.1.2

Multi-column layout across pages

Newsletter and catalog layouts with CSS columns keep flowing from page to page, with their gaps and column rules.

v4.2v42 engine

Media queries level 4

Print-specific styles and the current media features work as in the browser, so one stylesheet serves screen and paper.

v4.2v42 engine

Gradient text and @property

background-clip: text paints gradients into headlines, and registered custom properties supply the initial values of var().

v4.2v42 engine

Vertical writing

Japanese and Chinese vertical text as Chrome sets it: vertical glyph forms, text-combine-upright, sideways text and mixed scripts.

v4.2v42 engine
The pd4ml.com front page converted to PDF with the v42 engine, open in Adobe Acrobat Reader: navigation bar, dark hero section, customer logos and format tiles, laid out as in a browser
The pd4ml.com front page converted with the v42 engine and opened in Adobe Acrobat Reader. Download the PDF.
PAGES AND PRODUCTION

Page setup in CSS, and identical output everywhere.

CSS @page rules

Page size and margins, first, left, right and blank pages, and named pages for landscape tables or cover sheets, all set in your stylesheet.

v4.2v42 engine

16 page-margin boxes

Running headers and footers, page numbers and "page X of Y" counters go into the CSS margin boxes, with no extra templates.

v4.2v42 engine

Same output on every machine

v42 uses only the configured font set, @font-face fonts and the fonts bundled with PD4ML. Fonts installed on the host are never used, so a developer laptop, CI and the Docker container produce the same document.

v4.2v42 engine

Faster loading of web pages

Images, stylesheets and other remote resources load on several threads at once over kept-alive connections: see asyncResourceLoader().

v4.2v42 engine

Safe with untrusted HTML

Restrict resource loading to the locations you list, so HTML from users or other systems can't make the server fetch internal URLs or local files.

v4.2both engines

One parse, many formats

Lay a document out once and write it as PDF, DOCX, RTF, Markdown and page images from the same readHTML().

v4.2v42 engine
THE DOM API

Fix the document in Java, then convert.

Between readHTML() and the output, query the parsed document with CSS selectors, change text, attributes and styles, and insert content. layout() tells you where each element ends up on which page before the real output is written.

Useful for adding missing alt texts, removing interactive elements, or checking that a signature block didn't split across pages. DOM API: DMS and UA editions.

PD4ML pd4ml = new PD4ML();
pd4ml.useHtmlRenderer(Constants.LayoutEngine.v42);   // opt in
pd4ml.addAllowedResourceLocation("https://cdn.example.com/");
pd4ml.readHTML(new URL("https://example.com/invoice.html"));

// DOM API (DMS, UA): adjust the parsed document
Document doc = pd4ml.getDocument();
for (Element img : doc.querySelectorAll("img:not([alt])")) {
    img.setAttribute("alt", "Company logo");
}

pd4ml.writePDF(new FileOutputStream("invoice.pdf"));
COMPATIBILITY

Opt in when you're ready.

  • v40 stays the default. Existing applications produce the same output until they select v42.
  • Per conversion. Choose the engine for each document, and move templates over one at a time.
  • Everywhere PD4ML runs. The Java API, the Pd4Cmd command line (-engine v42), the JSP tag library and the language wrappers.
  • No JavaScript, as before. <iframe>, <embed>, <object>, <canvas> and <video> are shown as labelled placeholders.

Features marked v4.2 are part of the PD4ML v4.2.0 development snapshot: download it from the Downloads page or use 4.2.0-SNAPSHOT from the Maven repository. The other features are in the current releases, PD4ML v4.1.2 and v4.0.24. The release notes and What Is New in PD4ML v4.2.0 list every change.

MORE IN PD4ML 4.1 AND 4.2

Explore the other improvements

Try the v42 engine on your own templates.

Download PD4ML, request a free evaluation license and compare v40 and v42 output side by side.