Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Understanding the PDF file Format – PDF dictionary

1 min read

The basis of a PDF file is a set of linked PDF objects, and the key part of a PDF object is the PDF dictionary. So it is pretty important to understand how the PDF Dictionary works.

If you view a PDF object you will see something like this

2479 0
obj<<
/LastChar 89
/BaseFont /MXREUX+HelveticaLTStd-Roman
/Type /Font
/Encoding /WinAnsiEncoding
/Subtype /Type1
/FontDescriptor 2480 0 R
/FirstChar 32
/Widths [278 0 0 0 0 0 0 0 0 0 0 0 0 0 278 0 556 556 556 0 0 0 0 0 0 0 0 0 0 0 0 0 0 667 0 722 0 667 0 778 722 278 500 0 556 833 722 778 0 0 722 0 0 722 0 944 0 667]
>>
endobj

2484 0
obj<<
/Subtype /Type1C
/Length 886
/Filter /FlateDecode
>>
stream (rest of object ommiteed)

This shows 2 PDF objects (identified as object 2479 0 R and 2484 0 R). The PDF object starts with a number and then obj shows the start of the object. The PDF dictionary is contained between the << >> brackets. Object 2484 0 R also has some binary data at the end which comes after the word stream. The last part of the object is the word endobj

So lets have a closer look and see what is going on between those brackets. An entry in a PDF Dictionary consists of a pair of values – a key (which always starts with a / ) and a value (which can be many things). So /LastChar, /BaseFont, /Type, /Encoding, etc are all keys which are defined in the PDF file specification. It is possible to add your own keys which will be ignored by Acrobat. The order they are listed is not important as all keys and their values are read before anything happens with the object.

The type of value depends on the key, so /LastChar takes a number value, /BaseFont, /Type, /Subtype take a string constant value starting with a /, /Widths is a array of numbers and /FontDescriptor points to another object. All values can be stored in another value, so the value can also be an object (2480 0 R) which contains the actual data (number, string,etc).

The value pairs contain all the data for the PDF objects and now you know how they work.

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Enabling SVG Gzip Compression on Apache and NGINX

Gzip compression is a widely supported method of reducing the size of the content sent from a web server in order to improve the...
Leon Atherton
47 sec read

One Reply to “Understanding the PDF file Format – PDF dictionary”

  1. Is there anything in the PDF Reference related to this statement you made?:

    > The order they are listed is not important as all keys and their values are read before anything happens with the object.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.