Making the file smaller

The same document written twice, plainly and packed, with what each one weighs and what the packing saved.

Most of a PDF is lists of settings — one for the file, one for each page, one for each font, one for each clickable area. None of them is a block of data, so none of them is compressed, and each is written out in full. A file can instead gather them into blocks that are compressed together, and write the table saying where everything is as a block too.

The page you are reading was written that way, and it reports on a second document of twenty-four pages that was written both ways. The saving grows with the number of pages, because every page costs a handful of those lists. It is off unless you ask for it, and asking for it needs a file that says it is PDF 1.5 or later — a document that says less is refused rather than quietly written as something an older reader could not open at all.

What this example shows

  • One setting: everything that is not a block of data gets packed.
  • The table of contents of the file becomes a compressed block too.
  • The same document comes out either way: only its size changes.

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 same document is written in each of these languages. Open the one you want to look at.

Open the document in English Open the document in French

Read the Rust source Read the Python source

First page of Making the file smaller

What this document weighs

This document weighs 40,701 bytes.

The team wrote this example after measuring the documents above, so there is no earlier figure to set beside it. See every document measured.

Examples near this one

A minimal PDF

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

A boarding pass

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

Every example, by subject