PD4ML v4.2.0 is out. It inherits all bug fixes and improvements of PD4ML v4.1.2, and adds a second HTML/CSS layout engine, v42, with new features built on it: browser-compatible layout, CSS @page rules, a DOM API, Word output from the same layout as the PDF, and Markdown for LLM pipelines. The existing engine, v40, stays the default, so applications that don’t opt in keep their current output. Several improvements apply to both engines.
The v42 layout engine
- Select it with
useHtmlRenderer(Constants.LayoutEngine.v42)beforereadHTML(), or with the corresponding option of Pd4Cmd, the tag library and the language wrappers. Its layout is checked against Chrome’s print output. - Modern HTML and CSS: a tolerant HTML5 parser that repairs markup as browsers do, Flexbox, CSS Grid, multi-column layout continued across pages, vertical writing modes and media queries level 4.
- Page setup in CSS:
@pagerules for page size and margins, first, left, right and blank pages, named pages, and the 16 page-margin boxes with page counters. - Typography from the font: ligatures, real small capitals, old-style and tabular figures, fractions, stylistic sets and the letter forms of a language, with PD4ML’s own OpenType shaping.
- Vertical Japanese and Chinese text as in Chrome, with the fonts’ vertical forms, mixed scripts and
text-combine-upright. - The same output on every machine: fonts come only from the configured font set,
@font-facerules and the fonts bundled with PD4ML, never from the host. - Faster loading of web pages: remote images and style sheets are fetched by several threads over kept-open connections.
- Richer PDF/UA tagging: headings, sections, lists, tables with header scopes, links, and images and SVG with their alternate text.
DOM API
- Read and change the parsed document between
readHTML()and the output: query it with CSS selectors, edit text, attributes and styles, insert content, and find out where each element is laid out before writing the real output (DMS and UA editions, v42).
Word and Markdown output
- With v42, DOCX and RTF follow the layout of the PDF: positioned content, form controls, SVG and rounded boxes come out as editable Word objects, and multi-column sections as columns side by side.
- DOCX can embed the document’s fonts (
pd4ml.docx.embed.fonts) and passes CSS font features on as Word’s OpenType settings. - With the UA edition, Word documents are accessible too: headings, table header rows, the document language, alternate texts and the title.
- Watermarks appear in DOCX and RTF output, with both engines.
- New
writeMarkdown(): GitHub-flavored Markdown built from the same layout as the PDF, only the text a reader sees, in reading order, with optional<!-- page N -->markers so a RAG answer can cite the PDF page. Also in Pd4Cmd (-outformat markdown) and the Docker service (format=markdown). DMS and UA editions, v42.
Both engines
- CSS linear, radial and conic gradients, color emoji, SVG blur filters, and variable web fonts drawn at every weight their
@font-facerules name. - Smaller PDF files without any configuration: leaner page content, smaller font subsets and compressed object streams. Brotli compression for PDF 2.0 output as an opt-in.
- E-mail messages (
.eml) and saved web pages (.mht,.mhtml) are read like HTML (DMS and UA editions). - One
readHTML(), several formats: PDF, DOCX, RTF, Markdown and images from a single parse. - Resource loading can be restricted to listed locations, so untrusted HTML cannot make PD4ML fetch arbitrary files or URLs.
- The PDF optimizer can write linearized (“Fast Web View”) files, and the PDF object model reads Brotli-compressed streams.
The full list, with links to the manual sections and usage examples, is on the documentation page What Is New in PD4ML v4.2.0. Download v4.2.0 from the Downloads page, or use version 4.2.0 from the PD4ML Maven repository. We’d like to hear how your documents come out with the v42 engine: please report problems and differences from the browser on the support forum.
