Newsletters, catalogs, glossaries and price lists read better in narrow columns than in lines that run across the whole page. PD4ML v3 users have long relied on generateMulticolumn() for exactly that – and with PD4ML v4.0.24 and v4.1.2 the feature is back, rebuilt for the v4 rendering pipeline.

One call

PD4ML pd4ml = new PD4ML();
pd4ml.generateMulticolumn(2, 8, true);   // 2 columns per page, 8 mm gap
pd4ml.readHTML(new URL("file:newsletter.html"));
pd4ml.writePDF(fos);

The call is the same as in v3, so existing v3 code carries over unchanged.

How it works

  • The document is laid out to the width of a column, and the columns of each page are filled one after another. Every page break – the ones the layout finds as well as <pd4ml:page.break> – moves on to the next column; after the last column a new page starts.
  • <pd4ml:page.break multicolumn="true"/> starts a new page right away, for example for an appendix or a new chapter.
  • Page headers, footers, backgrounds and watermarks belong to the page, not to a column: they span all columns, and $[page] / $[total] count pages, not columns.
  • Footnotes are placed at the bottom of the column that refers to them; links and bookmarks point to the right column.
  • Any page format works: three columns on landscape A4 are one setPageSize(PageSize.A4.rotate()) away.

See it in action

Two new runnable examples in the pd4ml-examples repository, each with its HTML source and the resulting PDF:

Documentation

Availability

Multicolumn layout is part of the PD4ML v4.0.24 and v4.1.2 snapshot builds, already available for download and from the PD4ML Maven repository. It applies to PDF output; as in v3, it is ignored together with adjustHtmlWidth() and fitPageVertically().

Questions or a layout that doesn’t come out as expected? Let us know – we’d like to see your multicolumn documents.