Mark Stephens Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Understanding the PDF File Format: Document and Page level

1 min read

In my latest article on “Understanding the PDF File Format”, I want to to give you a better understanding of how a PDF file is structured and how this can impact on the way you create and use PDF files.

What is inside a PDF?

A PDF file is the binary data dump of the objects inside a PDF file. These are best imagined as a tree of linked objects which can be scanned down. There is one PDF tree for the whole document, with each Page having its own Object, so you can visualise a PDF as having a Document and a Page level.

What is at the Document Level?

The PDF will have a single tree of objects (which may be created by combining multiple reference tables). This will contain objects which are shared by all pages. These include:-

  1. An information object (with metadata as both fields and an XML structure).
  2. An encryption object (which is used to encrypt and decrypt all objects in the file).
  3. An ID (used for encryption).
  4. A form object (containing the FDF form objects for all pages or possibly the XML streams which define the actual forms and pages).
  5. Structure information on the flow of the data in the PDF.
  6. Other document content such as Thumbnails, etc.

What is at the Page level?

The page level contains the content specific to the so it will contain the unique contents, fonts and images for each page. It can also contain a list of Annotations (for just that page). Because the PDF is a tree it will inherit all the Document level values, and any common data up the tree. For example, a font could be shared by several pages.

In most PDF files, the font will be unique to each page, which is why our PDF to HTML5 converter writes out a font for every page.

Page and Document level?

Some objects (such as Interactive objects can appear at both a Page (in the Annots) and a Document (in the Form Object) level. So if you are parsing the PDF, you may need to allow for this.

Some objects such as CropBox and MediaBox can have Document level settings which are then used as the default settings unless over-ridden. So if a PDF contains one different page size, it would have a Document level MediaBox used for most pages and then then a unique page level MediaBox setting for just the odd page. This gives the PDF file format great flexibility.

I find that when I am working with a PDF file, thinking of it at the Document and the Page level helps to better understand how the file works and how I can optimise. Do you have any tips on understanding PDF files?

Want to learn more about PDF files?

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!

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (TwitterFacebook and Google+) or the Blog RSS.

Mark Stephens Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Hacking the NetBeans IDE – 4. Changing the way…

To help us prepare for our talks for our talks at Oracle CodeOne – “Writing Better Code (Faster) in the Apache NetBeans IDE ” and “Hacking...
Mark Stephens
1 min read

Leave a Reply

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