A minimal PDF

The smallest complete file: a page, and shapes drawn on it.

The smallest complete file the library writes: a document, a page added to it, a handful of shapes drawn on that page, and the bytes on disk. If you are reading the examples in order, this is where they start — everything else on this site adds to this skeleton rather than replacing it.

It exists for a second reason too. A unit test can only say one thing: the file looks right to whoever has just written it. Whether it really is a PDF only a reader can answer, so this file is what the engine's validity check opens.

What this example shows

  • A document, a page, and what is drawn on it. Nothing else.
  • Shapes drawn with the two plainest commands there are: fill, stroke.
  • The shortest path from an empty project to a file that opens.

The code, in full

The same document is written twice, once in each language. Both files are shown in full, with the code coloured on the server, and can be copied in one click.

The document itself

The document this example writes, ready to open.

Open the document in English

Read the Rust source Read the Python source

First page of A minimal PDF

What this document weighs

This document weighs 14,752 bytes, and weighed exactly as much before.

This document draws shapes and not one word, so it carries no font at all and there was nothing in it to take out. See every document measured.

Examples near this one

A landscape certificate

A landscape certificate whose border and seal are drawn line by line rather than placed as pictures.

A boarding pass

A boarding pass carrying the IATA BCBP string a gate scanner reads.

Every example, by subject