BlogEngineering

PDFs Don't Have Paragraphs. How Papaya PDF Reconstructs Editable Layout

A PDF preserves positioned drawing instructions, not paragraphs. Here is how Papaya PDF uses geometry and source structure to recover editable layout.

When you click a sentence in a PDF, you reasonably expect to select a sentence that wraps like one when you edit it. Most PDFs do not store that.

Drawing instructions, not documents

A word processor thinks in paragraphs, headings, lists, tables and margins. A PDF holds instructions for painting a finished page: choose a font and size, move the text position, show glyphs, draw a line or rectangle, fill a shape, place an image.

That keeps a page stable across printers and operating systems. It does not guarantee an editable paragraph object.

What the reader seesWhat the PDF may contain
One paragraphMany separate text operations
A spaceA cursor movement, with no space character
A letterA subset glyph with no clean mapping to the typed character
A tableText, thin rules, filled rectangles and repeated coordinates

This is why PDF editing is harder than it looks: the editor must infer structure without pretending the file stored it.

Lifting

Papaya PDF calls this lifting. The engine starts from the display list it renders the page with and builds more useful objects from its facts.

The question is not "Which text operation was clicked?" but "Which editable region does it belong to?" A clicked operation hints at intent but is rarely the whole object meant.

Signals behind a text region

Diagram in three steps: first, separate glyph runs scattered across two columns; second, the runs grouped into rows by shared baselines; third, the rows grouped into outlined blocks by small line gaps and shared left edges, with a large gap splitting the left column into two blocks and a column gutter separating the left and right columns.
Figure 1. Rows come from shared baselines; blocks come from small line gaps and shared left edges, split by large gaps and gutters.

No single coordinate or string marks a paragraph, so the pass weighs several signals.

SignalWhat it tells the engine
Shared baselinesFragments emitted separately (a word, glyph cluster or styled run) form one visual row
Horizontal gapsA word boundary where the literal space is missing, judged against the row, font and advances
Vertical gapsA small one is usually wrapped line flow; a much larger one may start a paragraph, a disclosure section or other content
Columns and alignmentGutters, shared left and repeated right edges, font and size patterns, and text density separate neighboring blocks

Fragment geometry is kept, so the engine can reason about a row and still edit and write its source.

Alignment matters for forms and reports. By paint order alone, aligned labels and values look like a paragraph; ignoring gutters, columns become one scrambled stream.

Each recovered box is also tied to its source operations, so the original text is suppressed when the editable object takes over. That separates an engine-backed edit from a cover-up: not browser text over a screenshot, but an object the engine renders and saves as a valid PDF.

Conservative inference

Layout recovery is inference, so the engine must know when not to invent structure.

A few thin lines do not make a table: a tax form can use a table's rectangles and rules for independent fields. A short aligned group may be a list, form, notice or prose.

With weak evidence, Papaya PDF should fall back to ordinary text handling or an explicit selection. A wrong table is worse than a missed one: it changes the user's document model and makes later edits surprising.

So production rules use reusable signals (baselines, gaps, alignment, styles, source order, repeated structure), not a form label, vendor name or document vocabulary.

Deterministic facts first

Born-digital PDFs hold exact facts a model should not rediscover from pixels: glyph positions, text matrices, font resources, vector paths, fills, annotations, clipping and source-operation order.

Building on them keeps the core lifting path inspectable, local-first and tied to the PDF being edited.

Learned layout models and OCR can help with ambiguity or scans, but should only propose or rank candidates. The engine decides what becomes editable, how the source is suppressed, and whether the result can be written back safely.

Status

CapabilityState
Per-operation text lifting into editable text boxesSupported
Selected-region table liftBasic, a rough prototype; next is measuring it on real, geometry-rich PDFs and tightening its failure boundaries
Full structural paragraph liftingBeing built: paragraph clustering, stable identity, word and paragraph selection, deeper reflow across arbitrary PDFs

We would rather say so plainly than pretend every PDF is already a Word document.

The aim: recover the smallest trustworthy structure that makes the next edit behave like an edit to a document the user authored.

For the practical side, try editing text in a PDF or read about the hidden font problem in PDFs.