Fonts embedded in the file

Send a document to somebody who does not have your house font and one of two things happens: their reading software quietly puts another one in its place and your layout moves, or it draws empty boxes where the letters were. Carrying the font inside the file is the only cure, and it is the first thing a commercial printer will ask you for before accepting the job.

Carrying the whole font would be wasteful — it has thousands of shapes in it and a letter uses a few dozen — so the file takes only the ones it draws. That is the easy half. The hard half is that the words have to come back out: select a sentence in the finished document, copy it, search it, or have it read aloud, and it must still be words rather than a picture of words. The file therefore carries a small list saying which letter each drawn shape stands for, and the team pulls the text back out of the published file to make sure it does.

What this example shows

  • A font carried inside the file, cut down to the letters drawn.
  • Text that can still be searched, copied and read aloud.
  • Any font you hand it, not one fixed choice.

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

Fonts embedded in the file, first page

Optimised, this document weighs 13.7 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 minimal PDF

Two identical pages carrying the bones of an invoice in plain shapes, and not a word of text: a file of a dozen kilobytes, with no font embedded.

Making the file smaller

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

Letters you draw yourself

A tick, a cross and a dash drawn by the program, added to the document as a font, and set among ordinary words.

Every example, by subject