Pular para o conteúdo
NewKitApp

Noções de PDF

How PDF Files Work: What's Inside a PDF and Why It Matters

A plain-language tour of the PDF format: pages, fonts, images, text, forms and metadata. Knowing the structure explains why PDFs behave the way they do.

NewKitApp 9 min de leitura

Nossos guias estão disponíveis em inglês e indonésio. Os artigos abaixo abrem em inglês.

You probably open a dozen PDFs a week without thinking about what they are. Then one day you try to copy a paragraph and get gibberish, or a 3-page form weighs 15 MB, or a merged file loses its form answers, and the format suddenly feels mysterious.

It isn't mysterious. A PDF follows a small set of ideas that Adobe published in 1993 and that became an open ISO standard (ISO 32000) in 2008. Once you know those ideas, the strange behaviour of PDFs starts to make sense, and you can pick the right tool for any job. This article walks through the format from the outside in, without assuming any programming knowledge.

The goal: a page that looks the same everywhere

Before PDF, sending a document meant sending a Word file, a WordPerfect file or some other editor's format. The recipient needed the same program, the same version and the same fonts, or the layout shifted: lines wrapped differently, pages broke in new places, a missing font got replaced by something else.

PDF solved that by describing the finished page instead of the editable document. A Word file says "here's a heading, here's a paragraph, wrap it to the page width". A PDF says "draw these characters at exactly these coordinates in exactly this font". There's no wrapping to recalculate, so the page looks the same on a phone, a Mac, a Windows PC and a printer.

That one design choice explains most of what you'll read below. PDFs are excellent at keeping a layout fixed and awkward at anything that requires changing it.

The basic structure

Open a PDF in a plain text editor and you'll see a mix of readable keywords and binary noise. Underneath, the file has four parts:

  1. A header, the first line, such as %PDF-1.7, naming the version.
  2. A body of numbered objects: pages, fonts, images, text streams, form fields.
  3. A cross-reference table listing where each object starts in the file, so a reader can jump straight to page 400 without reading pages 1 to 399.
  4. A trailer pointing to the document's root object and the cross-reference table.

The objects reference each other by number. The root points to a page tree, the page tree points to individual pages, each page points to its content and resources. Think of it as a small database of parts.

This structure is why tools can do some jobs cheaply. Rotating a page changes one number in one object. Deleting a page removes it from the page tree. Merging copies objects from several files into one and builds a new page tree. None of these need to understand what's printed on the page.

Pages and content streams

Each page object has a size (the "media box", in points, where 72 points make an inch), an optional rotation and a content stream. The content stream is a list of drawing operators, something like:

BT /F1 12 Tf 72 720 Td (Hello, world) Tj ET
0.8 0.1 0.1 rg 72 600 200 50 re f

In words: begin text, use font F1 at 12 points, move to position (72, 720), show "Hello, world", end text. Then set the fill colour to a red, draw a 200 by 50 rectangle at (72, 600) and fill it.

That's it. A page is a program that draws itself. Coordinates start at the bottom-left corner, which is why some PDF tools seem to place things upside down if they don't account for it.

Two things follow:

  • Colour is in the instructions. Converting a document to grayscale means rewriting every colour operator, which is how Grayscale PDF keeps text as text while removing colour.
  • Rotation is a separate setting. A page with /Rotate 90 has the same content stream as an unrotated page; the reader turns it when displaying. That's why Rotate PDF is instant and lossless.

Text: why copying sometimes fails

Look at the content stream again. "Hello, world" is drawn as one string at one position. But PDF makers often split text much more finely: a word at a time, or even a letter at a time when they adjust spacing. A justified paragraph might be hundreds of tiny strings, each placed at exact coordinates.

There are no paragraphs in a PDF, and often no spaces. When you see a space between two words, it may simply be a gap between two strings. When you copy text, the reader has to guess where words, lines and paragraphs begin by looking at positions. Usually it guesses well. Sometimes, especially with multi-column layouts, tables and justified text, it doesn't, and you get words glued together, lines in the wrong order or hyphens in the middle of words.

PDF to Text rebuilds reading order by grouping text fragments on the same baseline into lines, sorting lines from top to bottom and adding spaces where the gap between fragments is wide. It does a better job than copy and paste, but it's still reconstruction, not reading stored paragraphs.

Fonts and the "gibberish" problem

A PDF draws text using glyph codes, not letters. A font inside the file maps codes to shapes. To copy text, the reader also needs a map from codes back to Unicode characters (a "ToUnicode" table). Most PDF makers include one. Some don't, especially older or specialised software, and some deliberately scramble it. Without that map, the reader can draw the letters perfectly but has no idea what they are. Copying gives you strange symbols. No extraction tool can fix this reliably; the information isn't in the file.

Scanned pages contain no text at all

A scanned page is a single image. There are no text operators, just "draw this picture over the whole page". The reader has nothing to copy. To get text out of a scan, you need optical character recognition (OCR), which analyses the image and guesses the letters.

Images

Images are stored as separate objects, usually compressed with JPEG (DCTDecode in PDF terms) for photos or with lossless Flate compression for screenshots and graphics. The page's content stream says "draw image Im1 at this position and size".

An image's stored resolution and its displayed size are independent. A 4000-pixel-wide photo can be drawn in a 5 cm box. That's why PDFs get heavy: the file stores every pixel, even if the page only shows the image small. Compression tools like Compress PDF work by resampling these images to a sensible resolution and re-encoding them, leaving text alone.

Because one image object can be drawn on many pages, a logo used on every page of a report is stored once. That's also why splitting a document sometimes produces parts that are each almost as large as the whole: if every page uses the same large background image, every part needs a copy.

Fonts

PDFs embed fonts so the document looks the same on computers that don't have them. Embedding a full font can add hundreds of kilobytes, so most software embeds a subset with only the characters used. You'll sometimes see font names like ABCDEF+Calibri in a document's properties; the random prefix marks a subset.

If a font isn't embedded, the reader substitutes a similar one. The text may then reflow slightly within its line, or display wrongly for unusual scripts. Print shops ask for "all fonts embedded" for this reason.

The 14 "standard" fonts, such as Helvetica, Times and Courier, are guaranteed to exist in every PDF reader and don't need embedding. They only cover Western European characters, which is why tools that generate PDFs with them, like Markdown to PDF, can't print emoji or non-Latin scripts.

Forms

Interactive forms are a layer on top of the page. Each field (a text box, a checkbox, a dropdown) is an "annotation" object with a position, a value and an appearance stream that tells the reader how to draw the field with its current value.

Because fields live in a separate layer:

  • Some viewers display fields differently or not at all.
  • Merging documents can lose fields, because the form belongs to the document, not to the page.
  • Anyone who receives a filled form can change the answers.

Flattening solves all three. Flatten PDF draws each field's current appearance into the page content and deletes the field objects. The answers become ordinary page content.

Annotations

Comments, highlights, sticky notes, stamps and links are also annotations, layered on top of the page. Your reader shows them; you can hide or delete them without touching the page itself. Links are annotations with an action: "go to page 12" or "open this URL".

Metadata

Every PDF can carry information about itself: title, author, subject, keywords, the application that created it, the software that produced the PDF, and creation and modification dates. This lives in two places, an old "document information" dictionary and a newer XMP metadata stream in XML.

Metadata is easy to forget and surprisingly visible. Browsers show the Title field as the tab name. Search engines use it as the headline for PDFs in results. The Author field often contains the name of the computer's user account, which might reveal more than you intended. You can review and change it with Edit PDF Metadata, or strip it entirely with Sanitize PDF.

Encryption

A password-protected PDF has its content streams and strings encrypted, with the key derived from the password. Modern PDFs use AES-256. There are two passwords:

  • The user password opens the document.
  • The owner password controls permissions such as printing, copying and editing.

Permissions are flags that readers are expected to respect. They aren't cryptographic barriers: once a document is open, a determined user with the right software can ignore them. The open password is the real protection. Protect PDF and Unlock PDF handle both directions.

Incremental updates and hidden history

When you edit and save a PDF in some applications, they don't rewrite the file. They append the changes to the end, along with a new cross-reference table that points to the new versions of changed objects. The old objects remain in the file, unreferenced but present.

This "incremental update" feature makes saving fast and is required for digital signatures (the signed bytes must not change). But it also means a file can contain earlier versions of its content. A tool that copies pages into a fresh document, as merging and extracting tools do, leaves that history behind.

PDF versions and flavours

You'll see version numbers from 1.3 to 2.0. Newer versions added features: transparency (1.4), better compression (1.5), AES encryption (1.6, 1.7), and a cleaned-up specification (2.0). Almost every current reader handles all of them.

There are also specialised profiles:

  • PDF/A for long-term archiving: fonts must be embedded, no encryption, no external dependencies.
  • PDF/X for professional printing: strict colour handling and bleed definitions.
  • PDF/UA for accessibility: tagged structure so screen readers can follow reading order.

Courts and archives sometimes require PDF/A. Print shops may require PDF/X. For everyday use, a normal PDF is fine.

A quick way to look inside a PDF yourself

You don't need special software to peek at this structure. Open any small PDF in a plain text editor such as Notepad or TextEdit. Scroll past the binary sections and you'll find readable fragments: /Type /Page, /MediaBox [0 0 595 842] (an A4 page in points), /Font, /Producer (Microsoft Word). The numbers before obj are object IDs, and 12 0 R means "see object 12". Most of the content will look like noise because it's compressed, but the skeleton is visible.

Your PDF reader shows a friendlier view. In Adobe Acrobat Reader, Chrome or Firefox, open document properties to see the metadata, page size, PDF version and fonts. That's often enough to diagnose a problem, such as a huge file caused by a dozen embedded fonts, or a missing title that makes a browser tab show a file name instead.

What this means in practice

Knowing the structure helps you choose the right tool:

  • To combine or cut documents, work at the page level: merge, split, extract. These are fast and lossless because they move whole page objects.
  • To change how pages look (rotation, crop), change page settings, not content.
  • To add things (watermarks, page numbers, signatures), append drawing instructions to the page.
  • To shrink files, target images, not text.
  • To get text out, remember it's reconstruction, and scans need OCR.
  • To lock form answers, flatten.
  • To share safely, check metadata, attachments and hidden layers.

PDFs are built to keep a finished page fixed. Tools that respect that design, moving pages and adding layers rather than trying to re-flow content, give clean results. Tools that fight it, like converters that try to rebuild an editable Word file from positioned text, always involve some guessing. With that in mind, you'll know what to expect before you click the button.

Ferramentas usadas neste guia

Continue lendo