# What Is New in PD4ML v4.2.0

PD4ML v4.2.0 adds a second HTML/CSS layout engine, **v42**, alongside the existing one, and builds new features on it: browser-compatible layout, a DOM API, CSS `@page` rules, and Word output from the same layout as the PDF. The existing engine, **v40**, stays the default, so applications that do not opt in keep their current output. Several improvements apply to both engines.

{% hint style="info" %}
This page describes a development snapshot. Features and details can still change before the release.
{% endhint %}

## The v42 layout engine

Select it with `useHtmlRenderer(Constants.LayoutEngine.v42)` before `readHTML()` (or the corresponding option of the command-line tool, 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; CSS multi-column layout continued across pages; vertical writing modes; media queries level 4.
* **Typography from the font.** CSS font features applied with PD4ML's own OpenType shaping: ligatures, real small capitals, old-style and tabular figures, fractions, ordinals, swashes and stylistic sets, the letter forms of a language (`lang`), `font-feature-settings`, `font-kerning`, `font-synthesis`. See [CSS Font Features](https://pd4ml.com/docs/features/css-font-features-and-opentype-typography.html).
* **Vertical writing as in Chrome.** Japanese and Chinese vertical text with the fonts' vertical forms and metrics, wrapping into further columns, mixed scripts in bidi order, `text-combine-upright`, sideways text, images in vertical lines. See [Vertical Writing Modes](https://pd4ml.com/docs/features/vertical-writing-modes.html).
* **Page setup in CSS.** `@page` rules: page size and margins, first, left, right and blank pages, named pages, and the 16 page-margin boxes with page counters.
* **The same output on every machine.** Fonts come only from the configured font set, `@font-face` rules and fonts bundled with PD4ML; the fonts installed on the host are never used.
* **Better accessibility.** Richer PDF/UA tagging: headings, sections, lists, tables with header scopes, links, and images and SVG with their alternate text.

![The pd4ml.com front page converted to PDF with the v42 engine, open in Adobe Acrobat Reader: the navigation bar, the dark hero section with its stacked document illustration, the customer logos and the format tiles, laid out as in a browser](https://pd4ml.com/docs/assets/images/docs/whats-new-v42-pdf-in-acrobat.png)

The pd4ml.com front page converted with the v42 engine (A4, HTML width 1280 px), open in Adobe Acrobat Reader. Download the [PDF](https://pd4ml.com/docs/assets/images/docs/pd4ml-front-page-v42.pdf).

See [Usage Examples: Select The Layout Engine](https://pd4ml.com/docs/usage-examples.html), the [HTML5 element support matrix](https://pd4ml.com/docs/html5-element-support-matrix.html) and [CSS @page rules](https://pd4ml.com/docs/features/css-page-rules-page-size-margins-named-pages-and-margin-boxes.html).

## The DOM API

Java code can read and change the parsed HTML document between `readHTML()` and the output -- query it with CSS selectors, edit text, attributes and styles, insert content -- and can lay the document out to find out where each element ends up, before writing the real output. Part of the DMS and UA editions; v42 engine. See [DOM API: Modifying the HTML Document Before Conversion](https://pd4ml.com/docs/features/modifying-the-html-document-before-conversion.html).

## Word output from the same layout

With the v42 engine, DOCX and RTF output follows the layout of the PDF: positioned content, form controls, SVG and rounded boxes come out as editable Word objects. DOCX output can carry the document's fonts (`pd4ml.docx.embed.fonts`) and passes the CSS font features on as Word's own OpenType settings. With the UA edition, the Word documents are accessible as well: headings, table header rows, the document language, alternate texts and the title. Watermarks now appear in DOCX and RTF output with both engines. See [RTF and DOCX Output](https://pd4ml.com/docs/features/rtf-and-docx-output.html).

![The same page converted to DOCX, open in Microsoft Word: the layout matches the PDF, and the headline, the buttons and the navigation are editable text](https://pd4ml.com/docs/assets/images/docs/whats-new-v42-docx-in-word.png)

The same conversion written as DOCX, open in Microsoft Word. Download the [DOCX](https://pd4ml.com/docs/assets/images/docs/pd4ml-front-page-v42.docx).

## Graphics and text, both engines

* **CSS gradients**: linear, radial and conic gradients as backgrounds.
* **Color emoji**, drawn from a color font.
* **More scripts and letters**: Khmer lines break between syllables (v42); letters such as Polish ę, ł or ś print correctly without a configured font set (v42).

## Input and output

* **E-mail and saved web pages** (DMS and UA editions): `.eml` messages and `.mht`/`.mhtml` files are read like HTML. See [Converting E-mail Messages and Saved Web Pages](https://pd4ml.com/docs/features/converting-e-mail-and-saved-web-pages.html).
* **Smaller PDF files** without any configuration: leaner page content, smaller font subsets and compressed object streams. See [Compact PDF Output](https://pd4ml.com/docs/features/compact-pdf-output.html).
* **Brotli compression** for PDF 2.0 output, as an opt-in.
* **One parse, several formats**: PDF, DOCX, RTF and images from a single `readHTML()`.

## Security

Resource loading can be restricted to listed locations, so HTML from users or other systems cannot make PD4ML fetch arbitrary files or URLs. See [Restricting Resource Loading for Untrusted HTML](https://pd4ml.com/docs/features/restricting-resource-loading-for-untrusted-html.html).

## PDF tools

The PDF optimizer can write linearized files ("Fast Web View"), and the PDF object model reads Brotli-compressed streams. See [PD4ML PDF Optimizer](https://pd4ml.com/docs/pdf-tools/pd4ml-pdf-optimizer.html).

## Compatibility

* **v40 remains the default.** Nothing changes for existing applications until they select v42.
* **Not supported, as before:** JavaScript; `<iframe>`, `<embed>`, `<object>`, `<canvas>` and `<video>` are shown as labelled placeholders.

For the details of every change, see the [PD4ML Programmer's Manual](https://pd4ml.com/docs/pd4ml-manual.html) and the [usage examples](https://pd4ml.com/docs/usage-examples.html).
