You proofread the PDF of your family book and the first name looks spotless. Yet a search fails to find the person, or the text extracted for the index turns up a different letter. Should you fix the layout, change how you search, or go back to the source document used to generate the page? Those actions do not solve the same problem.
We start from four small PDFs containing three invented lines: “Anne Mercier”, “René Lenoir”, and “Les archives de la famille”. Two further files will then let us count overlapping occurrences. No client document enters these exercises. The extractions, searches, and page comparisons were actually executed; we distinguish their results from the proposed correction requests.
Receive the “Pantheon of 28 Legendary Chefs” Dossier (Free A4 PDF) + 5 Audio Stories
Instant complimentary access to our illustrated gastronomic & historical dossier, plus 5 DRM-free MP3 audio chronicles.
One page, four files, several outcomes
In our first file, called Control, the three lines are real text. The second, Wrong Letter, preserves their visual shape but maps the initial A to a B during text extraction. In Decomposed Accent, the visual appearance again remains identical; the é in René now corresponds to two successive characters, an e and a combining accent. The fourth file, Image, contains only a raster image made from rendering the Control file.
This last construction is deliberately specific. We did not scan a printed page and we ran no OCR—no optical character recognition on the image. We placed inside the PDF the image our own rendering had just produced. Here it preserves what our eyes read, without carrying the characters as extractable text.
We rendered all four pages at 72 pixels per inch. The four images are identical pixel for pixel at that resolution. The streams that draw the glyphs in the first three files are also identical. Their difference lies in a mapping attached to the font, called ToUnicode. Akash Choudhary’s article for callas, published by the PDF Association, distinguishes the mechanism that gives a character its visible shape from the one that retrieves its textual value. Our exercise deliberately alters the second.
Three different tools were used to extract the text: PyMuPDF, pypdf, and pdftotext. Their output spacing is not always identical, but their results for our names agree. Here is the summary useful for the book:
Scroll the table horizontally if needed.
| File | First line extracted | Second line extracted | Third line text |
|---|---|---|---|
| Control | Anne Mercier | René Lenoir | Present |
| Wrong Letter | Bnne Mercier | René Lenoir | Present |
| Decomposed Accent | Anne Mercier | Rene followed by combining accent, then Lenoir | Present |
| Image | No text | No text | No text |
A wrong name can be perfectly searchable
We next ran PyMuPDF’s search on each PDF. In Control, “Anne” returns one match and “Bnne” none. In Wrong Letter, the reverse happens: zero matches for Anne, one match for Bnne. Yet that latter search highlights a region where the eye still reads Anne.
This case calls for a clear editorial decision. Do not replace the first name in the book with what the extraction returns. Extracted output is not a new civil-status record. Our starting model reads Anne, and we know which mapping we altered. Copying Bnne into the index would turn a file defect into a spelling presented to the reader. The wrong name could then show up in cross-references, even though no one ever typeset it that way on screen.
The first correction request here targets the text the file allows you to extract. An instruction such as “replace the visible A with an A” would not describe our defect. Its shape is already what we expect. You must ask for the extracted character at that spot to map back to A, and then check the entire line. Merely saying that the name should become searchable would also fall short: Bnne is already searchable in this file.
For the typesetter, our request would be: restore Anne in the extracted text, preserve its visual appearance, and check René Lenoir. Control is a constructed baseline for comparison, not a repair we subsequently carried out in layout software.
Our change affects the code for capital A used by that font. In the exercise, it occurs at the start of Anne. In a real book, checking would therefore need to cover every other occurrence affected, well beyond a single index line.
When René is not found, he is not necessarily missing
In Decomposed Accent, the final letter of René is extracted as an e followed by a combining accent. That sequence is present in the output: the name has not been replaced by another and the text has not vanished.
We searched for two sequences: René with a precomposed é, and René with e followed by the combining accent. In Control, the first search returns a match and the second returns none. In Decomposed Accent, the results invert. These are the responses returned by our version of PyMuPDF, not a rule claimed for every PDF viewer.
The Unicode FAQ on normalization describes canonical equivalence and the NFC form. In our test, that operation makes both representations of René equal.
This check yields a different answer to the complaint “the first name cannot be found”. For Wrong Letter, extraction had substituted a different letter; applying NFC does not restore Anne. For Decomposed Accent, comparing after NFC matches the baseline cleanly. The same lack of a search hit therefore does not automatically call for changing the book’s spelling.
For the index, you can thus reconcile both extracted forms of René Lenoir without declaring a spelling mistake. That result concerns representations of our invented line; it does not prove that two historical people bearing that name were a single individual.
A ligature does not let you merge every spelling
To bound this comparison, we ran two further tests on text strings, separately from the PDFs. The first contrasts Office, with the presentation character fi, against Office, set with separate letters. The second contrasts Œillet against Oeillet. These are not names found in archives, but strings chosen to distinguish operations.
The Unicode FAQ on ligatures distinguishes encoded characters from glyph shapes chosen by a font. The test below compares strings directly, without testing ligatured typesetting.
Scroll the table horizontally if needed.
| Compared pair | Equal as-is | Equal after NFC | Equal after NFKC |
|---|---|---|---|
| René / decomposed René | No | Yes | Yes |
| Office / Office | No | No | Yes |
| Œillet / Oeillet | No | No | No |
NFKC removes certain compatibility distinctions, with a possible loss of information flagged by the FAQ. In our second pair, it makes the strings equal; in the third, the difference remains.
For a family book, these results do not provide a universal “merge name variants” button. If your indexing rule keeps spelling variants as separate entries, it should say so. If you add a cross-reference from one variant to another, you are making a presentation choice that computation alone does not justify for you. In our final pair, the program did not even treat the strings as equal; merging them would require another, explicitly chosen rule.
An index could keep Œillet and Oeillet as distinct entries and offer a cross-reference for review. Computation does not decide that pairing. Unlike Bnne in our altered file, these variants were not produced by a deliberately falsified letter.
A page image does not hold the same text to fix
The Image file yields neither Anne, nor Bnne, nor either representation of René. Extractions from PyMuPDF and pypdf are empty; pdftotext outputs only a form feed. All four search queries in our test return zero results. Yet the page’s visual appearance remains identical to Control in our rendered comparison.
The difference from Wrong Letter rules out reusing the same instruction. In Wrong Letter, a text mapping exists and returns the wrong character. In Image, our construction placed no font and no text on the page: it contains an image. Asking to replace the textual value of A there does not refer to an element that exists in the file.
For this exercise, we have the Control file from before image conversion. Simply selecting that file restores the correct text in our extractions. That option will not always be available for a family document received from a third party. We therefore do not turn our success into a promise that vanished text can always be recovered automatically. In a real project, the first question would be whether an earlier text-based version still exists and can be supplied.
Two visible Annes, but three extracted mentions
To continue the test, we added a second “Anne Mercier” line at the bottom of the Control page. The new file, Two Visible Mentions, thus contains two Anne Merciers, one René Lenoir, and the archives heading. All three extractors return the name Anne Mercier twice. Searching for that full string with PyMuPDF returns two distinct rectangles: one near the first line, the other near the bottom of the page.
We built a final file, Invisible Duplicate, by adding Anne Mercier once more at the exact coordinates of the first line, but without drawing that text. The second visible Anne, lower down, is kept. This intervention is deliberate; it does not stem from OCR or from a flaw discovered in a received document. It lets us ask another question: how many mentions should be recorded when several text objects occupy the exact same spot?
The results differ across tools. PyMuPDF and pypdf now extract Anne Mercier three times. The final occurrence in their output is the one added invisibly, placed after the other content during file creation. pdftotext retains only two occurrences. We do not infer the internal rule used by that third tool; we simply observe that the three outputs no longer agree on the count for this page.
The visual drawing of the two new files remains identical in our renders at 72 pixels per inch. We checked this separately with PyMuPDF and with the Poppler engine: each engine produces the exact same image before and after our invisible addition. This comparison does not claim that pixels from two different engines are always equal. Here, it keeps the two lines we want to record fixed while an extra text object enters the extraction.
Search yields a different tally from counting extracted words. PyMuPDF finds three rectangles in Invisible Duplicate. The first and third are identical; the second sits lower down. If we keep only one entry per strictly distinct rectangle in those results, two positions remain. Raw text counted three, yet those three mentions occupy only two places on our page.
One might try a quicker reduction: keeping only distinct names. That would leave a single string, Anne Mercier. That answer no longer points to two passages. It can serve to compile a list of names present, but it loses the second visible occurrence if our task is to locate every place where the name appears. The result “one” is therefore not an even cleaner version of “two”; it answers a different brief.
To prepare references to passages, we keep two inventory lines here. The first corresponds to the upper position, with two superimposed hits in the altered file. The second corresponds to the lower position, with a single hit. This presentation preserves the distinction between an extra presence in extracted text and a genuine second place to consult. Automatically deleting the last occurrence of every name would not accomplish this: the position of the addition in the output is a quirk of how we built the file, not a general property of duplicates.
The scope of the index also changes the expected answer. A name index that lists only one entry per page would show a single reference for Anne on this page. A register meant to locate both passages would keep both positions. If the family wants to count mentions in the text, it must first decide whether the superimposed object counts as what it calls a mention. That decision precedes choosing the number to publish; it cannot be replaced by summing an extractor’s output.
The rule of strictly equal rectangles is not presented as a ready-made process for every book. Here we know where we added the text and we kept the page without that addition. Offsets, multiple pages, or other layouts would require a different check. Nor do we suggest stripping every invisible layer from a received PDF. The useful result is more precise: for these files, three extracted mentions, two visible positions, and one distinct string are three reproducible counts serving different needs.
Scope of the tests
The tests use PyMuPDF 1.28.2, pypdf 6.20.0, and pdftotext 24.11.0; normalization calculations use the installed Unicode 15.1.0 data. They do not cover the Acrobat clipboard, screen readers, or full accessibility validation. Any remediation requests remain to be carried out in the chosen production tool.
