A self-paginating table

An invoice with three hundred lines on it. A stock list. A month of till receipts. None of them fits on one page, and none of them has a length you can count on either: the same report runs to four pages one month and eleven the next. Somebody still has to decide where each page stops — and that decision is where an empty page appears out of nowhere, or a row is cut in half, or a section title is left stranded at the foot of a page with nothing under it.

Here the whole table is handed over at once and works out its own pages. The heading comes back at the top of each one, the footnote sits under the last line of each one, and a section title stays with the rows it introduces. If the table ever reached a point where it could not go forward, it stops and says so rather than quietly adding an empty page — which is the fault nobody notices until a customer counts the pages.

What this example shows

  • One call, answering with what to draw on each of the pages needed.
  • Heading and footnote rows repeated on every page.
  • Section titles kept with the rows underneath them.

The source code, complete

Nothing is left out and nothing is simplified: this is the program exactly as it runs, for the developer who uses this library. The third is the description itself: a plain list of what the page has to say, which is what the service is sent.

Read the Rust source Read the Python source Read the JSON source

The document itself

Open the document in English Open the document in French

A self-paginating table, first page

Optimised, this document weighs 27.5 kB — at least 85 % lighter than most PDF generators would write it

The document is lighter than it was, and every page still looks exactly the same. See this document's row in the table of every example.

Examples near this one

A multi-page invoice table

Twelve invoice lines is one page and thirty is two, the second taking up the first's header and layout.

Cells merged down the rows

A specification sheet whose cells are merged down the rows: each group named once beside all of its rows, with one note beside them; the thin lines stop at those cells' edges, and a note too long for the rows it covers makes them grow.

Columns measured from their cells

One parts list twice: four columns sharing the width equally, then the reference, the quantity and the price each as wide as their own widest cell and the description given everything they leave.

Pictures inside table cells

A catalogue whose first column is a picture rather than text: four pictures of very different sizes and proportions, each fitted whole and undistorted into the cell the table gives it and standing against a different corner of it, claiming no width from its column and no height from its row.

Every example, by subject