Why getting your highlights out of a PDF is harder than it should be
Marking up a document is easy. Getting those marks back out as something you can work with — a set of quotations, a list of comments, a file another program can read — is oddly difficult, and the difficulty has a specific technical cause worth understanding. This piece explains how annotations are actually stored, why a highlight does not contain the words it covers, what makes some documents impossible to extract from, and how to mark up a document so that the notes are worth having later.
A PDF is a page description, not a document
The root of every difficulty here is that a PDF does not describe a document in the way a word processor file does. It describes a page: put this glyph at this position, in this font, at this size. There is no paragraph, no sentence, often not even a word — just a stream of instructions for painting marks on a rectangle.
That design is why PDFs look identical everywhere, which was the whole point when the format was created. It is also why every operation that requires understanding the content, rather than reproducing it, has to reconstruct meaning that was thrown away when the file was made.
Text extraction from a PDF is therefore always an inference. Good extraction is very good, and modern files usually carry enough extra information to make it reliable, but it is reconstruction rather than reading.
Annotations are a separate layer
Annotations do not live in the page content at all. They are a separate list attached to each page, and each one is a small record with its own type, position, colour, author, timestamp and comment text. This is genuinely good news: that part is structured data and can be read exactly.
It also explains a behaviour people find odd. A comment added in one reader appears in another, and can be edited or deleted there, because it was never merged into the page. The underlying document is untouched by highlighting it, which is why marking up a signed contract does not invalidate the signature.
The types are more varied than most people realise. Highlight, underline, strikeout and squiggly are text markup. Sticky notes, typed boxes, freehand drawings, shapes, stamps and file attachments are all annotations too, and all of them can carry a comment.
What a highlight actually stores
A highlight records four corners for each line it covers, expressed as coordinates on the page, plus a colour. That is all. It does not store the text underneath, because it does not need to: to draw a highlight you only need to know where to put the yellow.
So recovering the words means going the long way round. The page's content has to be interpreted — every text-positioning instruction, every font, every character width — to work out where each glyph sits. Then, for each highlight, the glyphs inside its corners are collected and put back into order.
This is why extraction takes a moment on a long document, and why it occasionally comes up short. Everything else about an annotation is a lookup; this one part is a reconstruction of the page.
Fonts are where it goes wrong
Once a font is embedded in a PDF, the codes in the content stream are not necessarily letters. They are indexes into that particular font's own glyph table, and a subsetted font — one that includes only the characters actually used — may number them in whatever order suited the program that made it.
Well made files include a mapping from those codes back to real characters. It exists specifically so that text can be searched and copied, and when it is present, extraction is exact. When it is missing, the codes are just numbers, and any attempt to guess what they mean produces confident nonsense.
That is the reason a careful extractor sometimes says nothing rather than something. A quotation you cannot trust is worse than an acknowledged gap, because the gap is visible and the wrong quotation is not.
Scans have nothing underneath
A scanned document is a picture of a page. If nobody has run character recognition over it, there is no text in the file at all — just an image and, if it has been annotated, some coloured rectangles drawn on top of it.
A highlight on such a page is perfectly valid as an annotation. It has a position, a colour, an author and possibly a comment, and all of that comes out cleanly. What cannot come out is the sentence, because the sentence was never in the file.
The test is simple and worth doing before you spend time: try to select the text in your usual reader. If the cursor draws a box rather than selecting words, the page is an image, and recognition software is the only route to the words.
Reading order is an assumption
Annotations come out of a file in whatever order the file lists them, which is usually the order they were made rather than the order they appear on the page. Sorting them by position is nearly always what a reader wants, and the natural rule is top to bottom and then left to right.
That rule is right for ordinary prose and wrong for two-column layouts, where it reads across the gutter and interleaves the columns. Academic papers, newspapers and many reports are laid out this way, so it is worth knowing before wondering why the order looks scrambled.
The same limitation affects tables, sidebars and anything with a caption beside it. There is no general solution that does not involve analysing the page layout, which is a much larger problem than reading the annotations.
Marking up so that the notes are useful later
Since the colour, the author and the comment all survive extraction perfectly, they are the parts worth using deliberately. A consistent colour scheme — one for evidence, one for objections, one for things to follow up — becomes a filter later, and costs nothing at the time.
Adding a short comment to an important highlight is worth far more than the few seconds it takes. The quotation tells you what the document said; the comment tells you why you cared, which is the thing you will not remember in three months.
Highlighting whole paragraphs is less useful than it feels. A highlight that covers everything conveys nothing when it comes back as a list, and a list of full paragraphs is just the document again. Marking the sentence that carries the point produces notes you can actually read.
Encryption, permissions and the ones that will not open
Some PDFs are encrypted. Where there is a password, the content genuinely cannot be read without it, and that is the intended behaviour rather than a bug in whatever is trying to open it.
Others carry permission flags that ask readers not to allow copying or editing while remaining readable. These are honoured by convention rather than enforced by mathematics, but the sensible thing for any tool is to respect them.
The practical route when a file will not open is to open it in the reader you normally use, with the password if you have one, and save a copy without protection. If you do not have the password, the answer is to ask whoever produced the file rather than to look for a way round it.
Why doing this locally matters
The documents people annotate are, almost by definition, the documents they are working on closely: contracts, drafts, medical letters, research under embargo, papers under review. That is precisely the category least suitable for uploading to a website in exchange for a convenience.
There is no technical reason it needs to be uploaded. Everything described here — parsing the structure, decompressing the streams, laying out the text, matching the highlights — is ordinary computation that a browser can do perfectly well on the machine in front of you.
The check is easy if you want to make it. Load the page, disconnect from the network, and then open the file. Anything that still works was never sending your document anywhere, and anything that stops was.
It is worth applying the same test to the other end of the process as well. Notes extracted from a confidential draft are as sensitive as the draft itself, and pasting them into an online notepad or a shared document undoes whatever care was taken opening the file. Save them to a folder you already trust with the original, and the chain holds all the way through.
