Skip to content

1.1.1 Hello World PDF

Felix Schütt edited this page Jul 5, 2017 · 7 revisions

Almost every programming course starts with a "hello world" program. Since PDF is a text-based format, why not try to read the simplest, minimal PDF file - see if you can figure out what's going on:

%PDF-1.4
1 0 obj
<< /Title (Hallo Welt) >>
endobj
2 0 obj
<< /Type /Catalog
   /Pages 3 0 R
>>
endobj
3 0 obj
<< /Type /Pages
   /MediaBox [0 0 595 842]
   /Resources
   << /Font << /F1 4 0 R >>
      /ProcSet [/PDF /Text]
   >>
   /Kids [5 0 R]
   /Count 1
>>
endobj
4 0 obj
<< /Type /Font
   /Subtype /Type1
   /BaseFont /Helvetica
   /Encoding /WinAnsiEncoding
>>
endobj
5 0 obj
<< /Type /Page
   /Parent 3 0 R
   /Contents 6 0 R
>>
endobj
6 0 obj
<< /Length 41
>>
stream
/F1 48 Tf
BT
72 746 Td
(Hallo Welt) Tj
ET
endstream
endobj
xref
0 7
0000000000 65535 f 
0000000009 00000 n 
0000000050 00000 n 
0000000102 00000 n 
0000000268 00000 n 
0000000374 00000 n 
0000000443 00000 n 
trailer
<< /Size 7
   /Info 1 0 R
   /Root 2 0 R
>>
startxref
534
%%EOF

This is a valid PDF document with exactly one DIN-A4 page an the text "Hallo Welt" ("Hello World") in the top left corner. In this case the file is in a valid Unix text format (used by macOS and Linux). In the Windows world, there is a slight difference because of the line breaks - on the Object 6:

6 0 obj
<< /Length 45
>>

... and on the xref-table:

xref
0 7
0000000000 65535 f
0000000010 00000 n
0000000054 00000 n
0000000111 00000 n
0000000288 00000 n
0000000401 00000 n
0000000476 00000 n
trailer
<< /Size 7
   /Info 1 0 R
   /Root 2 0 R
>>
startxref
578
%%EOF

Alright, this is fine and all, but what does everything mean. We'll cover everything in detail, but here's an overview:

%PDF-1.4

We declare this PDF file as version 1.4

1 0 obj
<< /Title (Hallo Welt) >>
endobj

The metadata of this document - in this case it's just the title.

2 0 obj
<< /Type /Catalog
   /Pages 3 0 R
>>
endobj

The "Catalog" object contains various references to objects (marked with the R) to aid the interpreter. In this case it's only a reference to the "Pages" dictionary.

Clone this wiki locally