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.
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.
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.
Multi-column layout across pages
Newsletter and catalog layouts with CSS columns keep flowing from page to page, with their gaps and column rules.
Media queries level 4
Print-specific styles and the current media features work as in the browser, so one stylesheet serves screen and paper.
Gradient text and @property
background-clip: text paints gradients into headlines, and registered custom properties supply the initial values of var().
Vertical writing
Japanese and Chinese vertical text as Chrome sets it: vertical glyph forms, text-combine-upright, sideways text and mixed scripts.

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.
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.
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.
Faster loading of web pages
Images, stylesheets and other remote resources load on several threads at once over kept-alive connections: see asyncResourceLoader().
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.
One parse, many formats
Lay a document out once and write it as PDF, DOCX, RTF, Markdown and page images from the same readHTML().
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"));
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.
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.
