liveBook · Manning

PDF

As explained in How Computers Make Books

PDF is a document file format designed to preserve a document's layout and visual appearance across systems.

PDF preserves a multipage document’s appearance while it travels from one computer, printer, or reader to another. A page can combine glyphs from fonts, pixel-based images, and line drawings; together, those ingredients can make a book page. PDF can also carry metadata, such as an interactive table of contents. section 11.3 section 11.6

Think of a PDF page as a small set of drawing instructions. Its content stream contains numbers, strings, and operators: commands can position text, choose a font and size, draw text, trace lines, and place an image. Around that stream sits file structure describing pages, resources, and the document catalog. section 11.4

A simple page can be assembled in stages:

  • Position text, begin a text section, select a font, draw the characters, and end the text section. section 11.4
  • Add vector lines after the text; unlike pixels, these lines scale smoothly for viewing or printing. section 11.4
  • Place a small pixel image by defining its width, height, gray color space, bit depth, and image data, then scale it on the page. section 11.4
  • Wrap the page data in numbered objects, then provide a cross-reference table and trailer so a reader can locate them. section 11.4

A tiny “Hello, World!” page

One worked page moves to a position, sets font F0 to 36 points, and draws “Hello, World!”. Two short line segments underline it around the comma. A 5×5 gray gradient is then enlarged 100 times, making the difference between compact image data and its displayed size easy to see. section 11.4

Listing 11.4 Our PDF skeleton
1 0 obj  #A
<</Type /Pages /Kids [3 0 R] /Count 1>>
endobj
2 0 obj  #B
<</Length 235>>
stream
\textit{(all of our page data from above)}
endstream
endobj
3 0 obj  #C
<</Type /Page
  /Parent 1 0 R
  /Resources
    <</Font
      <</F0 <</Type /Font /Subtype /Type1 /BaseFont /Times-Italic>>>>
    >>
  /MediaBox[0 0 300 200]
  /Rotate 0
  /Contents[2 0 R]
>> 
endobj
4 0 obj  #D
<</Type /Catalog /Pages 1 0 R>>
endobj
xref
0 5   #E
0000000000 65535 f
0000000015 00000 n
0000000066 00000 n
0000000163 00000 n
0000000348 00000 n
trailer
<</Root 4 0 R /Size 5>>
startxref
393
%%EOF

Inspect the compact file skeleton to see page objects, the content stream, font resources, the catalog, and the cross-reference table together. section 11.4

PDF suits print and electronic publication when a fixed page layout matters. Reflowable eBooks with few graphics may instead use formats designed for eBook devices. section 11.6

How How Computers Make Books covers it

How deep it goes
Works through constructing a small PDF’s drawing commands and file skeleton, while deferring matrix mathematics and many format details.
Examples
Uses a reproduced page, an interactive table of contents, “Hello, World!” text, underlining, and an enlarged 5×5 gray image.
What it assumes
Introduces page-drawing operations directly, while treating the mathematics of transformation matrices as beyond scope.
What you can do after
Build it from scratch as a small PDF containing positioned text, vector lines, an inline image, and document objects.
How it connects
Connects fonts, glyphs, pixel images, vector graphics, metadata, page layout, and reflowable eBooks.

Also explained in

Compare how 2 books explain PDF →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of How Computers Make Books. The section links point to the parts of the book it draws on.