Leon Atherton Leon has over 15 years’ Java experience and leads BuildVu, also contributing to cloud services and internal tooling. Wearing many hats across technical and growth roles as a core member, he enjoys motorsport, strategy games, and software side projects.

Understanding the PDF File Format

6 min read

We have been working with PDF files since 1999 and built our own software to parse, render, and convert them. In that time we have developed a detailed understanding of how the format works at a technical level, not just how to use it, but why it is designed the way it is.

PDF (Portable Document Format) was created by Adobe in 1993 to solve a specific problem: a document should look identical regardless of the device, operating system, or application used to open it. It achieves this by embedding everything needed to render the file, including fonts, images, colour profiles, and layout instructions, directly inside the file itself. The format was standardised as ISO 32000 in 2008, and PDF 2.0 (ISO 32000-2) followed in 2017 with improvements to encryption, digital signatures, and accessibility.

What makes PDF technically distinctive is its page-description model. Rather than storing text as a linear stream as HTML does, PDF describes exactly where every character, shape, and image should appear on a fixed coordinate plane. This is why PDF renders consistently across devices, but also why editing, text extraction, reflow, and accessibility are hard engineering problems with no clean solutions.

All the technical knowledge we have accumulated is documented in the articles below, organised by topic. There is also a Glossary of PDF Terms covering the key vocabulary used throughout the format.

PDF File Structure & Syntax

Every PDF is built from a small set of primitive object types: booleans, numbers, strings, arrays, dictionaries, and streams, assembled into a structure that describes pages, resources, and metadata. The file begins with a header identifying the PDF version, followed by a body of objects, a cross-reference table that allows random access to those objects, and a trailer pointing to the document root. Understanding that structure is the foundation for everything else: rendering, extraction, editing, and repair.

Images in PDF

PDF supports raster images (JPEG, JPEG 2000, JBIG2, raw bitmap) and treats vector graphics as drawn paths rather than embedded files. Images are stored as stream objects with associated filter chains that handle compression and colour transformation. A single image object can pass through multiple filters before producing pixel data, which is why decoding PDF images correctly requires a more careful implementation than most developers expect.

Color Handling in PDF

PDF colour support is one of the most sophisticated parts of the specification. The format supports DeviceRGB, DeviceCMYK, DeviceGray, Lab, ICC-based colour spaces, and indexed palettes, with colour transformations definable at the individual object level. This matters in print production workflows, where incorrect colour handling produces commercially unacceptable output, and in any application where colour fidelity across devices is a requirement.

Text in PDF

Text in PDF is not stored as readable strings. It is encoded as sequences of glyph IDs mapped through font encoding tables, which is why copying text from a PDF often produces garbled output, and why text extraction is an active engineering problem rather than a solved one. The articles in this section explain how that encoding works, where it breaks down, and what can be done about it.

Fonts in PDF

PDF supports Type 1, TrueType, OpenType, and CID-keyed fonts, and can embed them fully or as subsets to reduce file size. When fonts are not embedded, viewers substitute alternatives using metrics stored in the file, which is a common source of rendering differences across platforms. The CID font system, designed for East Asian character sets with tens of thousands of glyphs, adds significant complexity that most developers encounter only when something breaks.

PDF Forms, Annotations & Interactive Elements

PDF forms exist in two incompatible formats: AcroForm, the original standard defined in the core PDF specification, and XFA, an XML-based format introduced by Adobe and effectively deprecated after Adobe Reader 2021. AcroForm is the format that matters today. Annotations cover a broader category that includes hyperlinks, comments, stamps, and digital signatures, each defined by their own dictionary structure within the file.

PDF Standards and Accessibility

The base PDF specification is supplemented by a set of ISO sub-standards for specific use cases. PDF/A restricts the format for long-term archival by prohibiting features like encryption and embedded JavaScript. PDF/X defines requirements for print-ready exchange. PDF/UA mandates the tagging and logical structure needed to support assistive technologies. PDF 2.0 (ISO 32000-2) consolidated many of these requirements into the core specification and introduced improvements that affect how compliant files should be created and processed today.

PDF File Encryption

PDF supports encryption from 40-bit RC4 through to 256-bit AES, with separate controls for opening a document and for restricting operations such as printing, copying, or modifying content. The permission model is enforced by the viewer rather than the operating system, which has specific security implications that are worth understanding before relying on it.

PDF Compression

PDF applies compression at the stream level, meaning individual objects within the same file can each use a different algorithm. Flate (zlib/DEFLATE) is the most common for general content. CCITT and JBIG2 are optimised for black-and-white images. JPEG and JPEG 2000 handle photographic content. Choosing the wrong algorithm for a given content type has a measurable effect on both file size and decode performance.

Quick Tutorials

Code-first examples for converting PDF files in production workflows across multiple languages. These tutorials use BuildVu, our PDF to HTML5 and SVG conversion tool, available as both a cloud service and a server deployment.

Converting PDF to HTML

Converting PDF to SVG

Guides

Frequently Asked Questions

Questions we are regularly asked by developers working with PDF files in code.

Build Your Own PDF File

The fastest way to understand how PDF works internally is to write one from scratch. This series walks through creating a valid PDF in a text editor, starting from raw object types and building up to a complete document with text and path drawing. It covers the object structure, cross-reference table, page tree, and graphics state, the internals that library abstractions hide but that matter when something goes wrong.

Our PDF Software

We build Java-based PDF tools used by companies worldwide. JPedal is our Java library for developers who need programmatic access to PDF content, covering rendering, text extraction, annotation handling, and form processing. BuildVu converts PDF to clean HTML5 or SVG, suitable for browser display without a plugin. FormVu converts PDF forms to HTML forms, preserving field behaviour in native markup.



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
Leon Atherton Leon has over 15 years’ Java experience and leads BuildVu, also contributing to cloud services and internal tooling. Wearing many hats across technical and growth roles as a core member, he enjoys motorsport, strategy games, and software side projects.

15 Replies to “Understanding the PDF File Format”

  1. Hello, JPedal team 🙂
    First of all, allow me to express my satisfaction for reading such simple and clear PDF knowledges background. This is really helpful for who just starts into the PDF world. Thank you for this great job.
    I found these posts while looking for a *real* way of doing some redacts. I thought I had everything when I found ‘pdfedit’ (with a combination of its ‘replaceText’, its ‘findText’, its ‘drawRect’ and its ‘flattener’ functionalities), but then the ugly truth came up: sometimes not all characters are available. I guess it’s embedded fonts fault, but I am not quite sure. Here is when I started to read your posts 😉
    The fact is, I guess I will be able to implement a functional redact feature if found the way to ensure my replacement char (the one I use to replace each char of the redacted phrase) is in fact available. I see two scenarios here:
    1- the char is available (and so, everybody is happy :P), or
    2- the char is not available, but I am able to insert it to the right (embedded?) font.
    Could you help me to accomplish this, please? Some hints could be appreciated.
    Thanks in advance.
    Best regards and keep this spirit!


    Alejandro

  2. Hello Leon,
    thanks for your work here. This is a really nice collection of helpful hints and tips. I’m searching the web looking for some explaining word on how to embed a XML file to a PDF/a3 file by code. Can you help me?
    Kind regards,
    Al Mudy

  3. I have a question.
    What is the data format used in PDF to draw table. Is there some type of native table object in PDF we can use or is it just a vector graphic that paints a table. and how table extraction done in PDF content extraction libraries.
    Could you please explain this.

    1. If the PDF was created with additional tagged meta data then there may be tags (there is no specification for these so they might be HTML or some custom user creation). Most files do not have this feature enabled so I am afraid it is usually just content painted in an arbitrary order which your brain then interprets as a table.

  4. Hi Thanks for the excellent guide it helped me to understand this much better.

    I have a question though. Some PDF’s which I read using the PDFSharp Library for Visual Studio. When I grab the text from a page.

    I get weird text.

    Instead of it being in clear text it seems to be encoded or possibly encrypted
    I.E
    Td
    (/0\(11$2#\(11#$2’3#45’67″$8) Tj

    Reading Chapter 9 of PDF 32000-1:2008 I cant gather if this is a font encoding or not.
    How can I go about decoding the above text ?

  5. A pdf file was edited using iTextPdf programmatically. The PDF has a few radio buttons. I can see the resulting pdf file in Chrome browser without issues, However when I open the same file in Acrobat Reader, radio buttons are not showing up in the file.
    What is missing here?

  6. Hello Mark, your blogs are amazing. I am looking for some technical to develop a software that can edit PDF files (text and images), like Foxit Reader. Have you and your colleagues done this, can you give me some advice. Thank you and Best Regards

    1. Many thanks for the compliment! I will pass on your feedback to the team. To answer your question we had considered in the past but have chosen to focus on our current product range for developers.

  7. Hello Mark – at my last job as a software engineer, I worked with a third party PDF parser (PDFLib) to extract metadata (fonts, colors, page size, document info, etc.) – and arrived at a pretty good Java API to retrieve detailed metadata in json and protobuf format. Unfortunately the tool I was using could not extract page background color, at least according to the vendor when we contacted them about this. I was incredulous that such a simple attribute as page background color could not be retrieved. Anyway, now that I have retired (that was my last full time job), I plan to see if I can crack this issue in my own time – obviously I don’t have access to the source code I developed at my last job but all I really want to do for now is to discover how the PDF specification represents page background color, chose a parser that allows me to extract that, and write a simple demo utility that extracts that.
    Any thoughts? Thanks in advance.

    1. Hi Chris,

      It is certainly an interesting problem. What do you mean by page background colour? There is no global setting for this value and the final colour of any pixel will depend on parsing and executing the PDF commands – the easiest way to get this is to rasterize the page so you get the end result, unless you mean colour behind text. So it is not a simple task.

      As regards recommending Open Source PDF libraries, it really depends what language you want to use. You have PDF.js (Javascipt), PdfBox/iText (Java) or xpdf (C).

  8. Thanks for that Mark. I wasn’t aware that there is no single setting, although of course it’s easy to set from Acrobat. Regarding rasterizing the PDF, I will certainly look into that, but yes the problem the software was trying to address was to detect ‘hidden’ text: that is text with identical color as its background.

    Likely I will be using Java or even Python (juts for fun!)

Comments are closed.