# How it works — Edit My PDF

> How Edit My PDF reads a PDF, makes its fonts typeable, fits every line to its printed width, and writes edits back as real text, all inside the browser.

Canonical: https://editmypdf.dev/how-it-works/

A PDF is not a document with paragraphs. It is a list of drawing instructions that happen to place glyphs. This is how Edit My PDF turns those instructions back into text you can edit, and back again into a PDF.

1.  Step 01
    
    ## The page is read, not just drawn
    
    pdf.js renders the page and hands over its text items and the drawing operators that produced them.
    
    pdf.js renders each page to a canvas and, alongside it, hands over two things: the page's text items with their positions and fonts, and the list of drawing operators the page used. From the operator list Edit My PDF walks the glyph stream and records, for every glyph, the character and word spacing in force when it was drawn and the font size it was selected at.
    
    Lines, filled boxes and images are collected too. Rules that cross form tables; a box painted after a run of text hides it, so that text is not offered for editing.
    
2.  Step 02
    
    ## The fonts become typeable
    
    A corrected copy of each embedded font is registered so every character maps to the glyph the page used.
    
    pdf.js converts every embedded font to OpenType and registers it in the browser. In those converted fonts each glyph sits at a private-use code and the Unicode entries are only a courtesy, so a ligature can occupy a plain letter's slot. Edit My PDF builds a corrected copy of each face from the glyphs the page actually used, with a Unicode table that maps every character to the glyph the page drew for it, and registers that copy as the face you type in.
    
3.  Step 03
    
    ## Every line is fitted to its printed width
    
    Letter and word spacing are solved per line so the editor opens exactly as wide as the page drew it.
    
    Text items are grouped into lines and lines into blocks: a heading, a single line, or a paragraph. For each line the editor measures its text in the page's face and compares it with the width the page drew. Letter spacing takes the PDF's own character spacing plus any mismatch between the font's advances and the page's; word spacing takes the rest. The converted fonts have no space glyph, so without this step every line with spaces would open a few points narrower than it prints.
    
    A paragraph keeps the page's line breaks, each line's own baseline and its own indent, so it opens looking exactly as printed. The baseline of the editor's first line is measured on a hidden line box rather than computed, because browsers round font metrics to whole pixels.
    
4.  Step 04
    
    ## You type in the page's own face
    
    A click samples the page's pixels, snapshots the neighbours and opens a styled-span editor in place.
    
    Clicking a text element samples the page's pixels under it for the background colour and any underline, snapshots the runs to its right that would have to move, and opens an editor at the exact position. A paragraph that mixes bold, italic and regular text is one editable block made of styled spans; typing continues in whatever face the caret sits in.
    
    Until you change a line, it stays as the page set it. From the first edit onward the paragraph's soft line breaks turn back into spaces so the text flows again inside the paragraph's own column, while the lines above the edit keep their printed layout.
    
5.  Step 05
    
    ## The download is a real PDF with real text
    
    The original strings leave the content stream and your words are written in a subset of the page's font.
    
    On export the original strings under each edit are removed from the page's content stream and replaced by an equal advance, so nothing else on the page moves. The edited words are written as text in a subset of the page's font, positioned word by word where the editor showed them. Pencil strokes, shapes, text boxes, emoji and signatures are written as vector or image content with pdf-lib.
    
    When a face cannot be embedded, or a typed character has no glyph in it, that one edit is painted as an image at three times resolution instead. The file you opened is never modified.
    

## What it does not do

Edit My PDF does one job, editing the text on the page. These are the cases it leaves alone, and the [comparisons](https://editmypdf.dev/compare/) say which tools do them well.

-   Scanned pages are images; there is no OCR, so their text cannot be edited, only covered.
-   Password-protected PDFs are refused.
-   Text drawn by a Type 3 font or by a font the PDF did not embed opens in a fallback face and exports as an image.
-   Text inside form XObjects (reused drawing blocks) is covered on export rather than removed.
-   There is no merging, splitting, page reordering, compression, conversion or form filling.
-   Everything happens in memory, so a very large file is limited by what your browser can hold.

[Open a PDF](https://editmypdf.dev/app/) [Read the engineering posts](https://editmypdf.dev/blog/)

---

Markdown version of https://editmypdf.dev/how-it-works/. Every page of Edit My PDF has one at the same address with .md appended; the index is https://editmypdf.dev/llms.txt.
