Mark Stephens Mark founded the company and has worked with Java and PDF since 1997. The original creator of the core code, he is also a NetBeans enthusiast who enjoys speaking at conferences and reading. He holds an Athletics Blue and an MA in Mediaeval History from St. Andrews University.

Multiple trailers in a PDF file

2 min read

TL;DR

  • Multiple trailers allow for Incremental Updates in PDFs.
  • New changes (data/objects) are appended to the file end, preventing a full rewrite.
  • Each trailer uses a /Prev pointer to link to the preceding update.
  • This mechanism is key for speed and maintaining digital signature validity.

What are Multiple Trailers in PDFs?

Multiple trailers in a PDF file are the result of “Incremental Updates.” Instead of rewriting an entire file when a change is made, the PDF specification allows new objects (like text edits or digital signatures) to be appended to the end of the file.

This creates a chain of trailers, linked by /Prev pointers, that allows a PDF viewer to reconstruct the most recent version of the document without modifying the original data.

What are PDF Incremental Updates?

The PDF file format is designed for efficiency and flexibility. When you edit a PDF (for example, using “Save” instead of “Save As”), the software does not always rewrite the gigabytes of data that might exist in the file.

Instead, it performs an Incremental Update. It writes the new or modified objects to the end of the file stream, followed by a new Cross-Reference (XRef) table and a new Trailer.

  • Original File: Contains Objects 1, 2, 3, and 4, ending with a Trailer.
  • Update: You modify Object 4 and add a new Object 5.
  • Result: The file now contains the original objects, followed by the new Object 4′, Object 5, and a second Trailer that tells the viewer to ignore the old Object 4.

How a PDF Viewer Reads Multiple Trailers (The Process)

For a PDF viewer to display the correct version of the document, it must follow a specific read order defined by the ISO 32000 standard. Here is the step-by-step process a viewer uses to handle multiple trailers:

  1. Read from the End: The viewer reads the very end of the PDF file (the last 1024 bytes) to locate the startxref keyword.
  2. Locate the Latest Trailer: The startxref value points to the byte offset of the most recent Cross-Reference (XRef) table and Trailer.
  3. Identify New Objects: The viewer reads this new table to find the locations of the latest objects (e.g., the new version of Object 4 and the new Object 5).
  4. Find the /Prev Pointer: Inside the new Trailer dictionary, the viewer looks for the /Prev key. This key contains the byte offset of the previous XRef table.
  5. Trace the Chain Backwards: The viewer jumps to the location specified by /Prev to read the older XRef table.
  6. Merge the Data: It loads the older objects (1, 2, and 3) but ignores the old Object 4 because a newer version was already found in the previous step.
  7. Repeat or Stop: This process repeats until a trailer is found with no /Prev key, indicating the start of the original file.

Why is this Feature Important? (Practical Use Cases)

The ability to have multiple trailers and append data is critical for several modern PDF workflows:

  • Digital Signatures: When you digitally sign a PDF, you must not alter the original bytes of the file, or the previous signatures will become invalid. Incremental updates allow the new signature to be appended safely to the end.
  • Speed and Efficiency: If you correct a typo in a 1GB architectural plan, the software only needs to save a few kilobytes of data (the new text object and trailer) rather than re-saving the full 1GB file.
  • Audit Trails & Version Control: Because the old objects are never deleted (only dereferenced), it is technically possible to “roll back” the PDF to a previous state by removing the appended data.

FAQs

Q: Does appending data increase PDF file size?

A: Yes. Incremental updates keep old objects in the file to preserve version history. To reduce file size, use “Save As” to rewrite the file and discard unused data.

Q: What is the /Prev pointer in a PDF?

A: It is a key in the trailer dictionary that points to the byte offset of the previous Cross-Reference table, effectively linking the chain of updates together.

Q: Can a PDF have infinite trailers?

A: Theoretically, yes. However, a very long chain of updates will eventually slow down file loading speeds, as the viewer must process every trailer in the sequence.



Our software libraries allow you to

Convert PDF files to HTML
Use PDF Forms in a web browser
Convert PDF Documents to an image
Work with PDF Documents in Java
Read and write HEIC and other Image formats in Java
Mark Stephens Mark founded the company and has worked with Java and PDF since 1997. The original creator of the core code, he is also a NetBeans enthusiast who enjoys speaking at conferences and reading. He holds an Athletics Blue and an MA in Mediaeval History from St. Andrews University.