How artificial intelligence works when matching a printed table of contents to a scanned PDF begins with a frustrating textbook problem. The contents page says ‘Chapter 4: Energy — 57’, but clicking page 57 in the PDF viewer opens a different chapter. The book might contain an unnumbered cover, acknowledgements, Roman-numbered introductory pages and a title page before its printed page one. The physical position of a page in the PDF file is not necessarily the number printed on that page.
Did you know that reading every contents entry correctly does not make its link correct? An OCR engine may extract the heading and printed number, but another stage must locate the corresponding chapter opening in the actual document. If pages are missing, duplicated or reordered, one constant page offset may not work. Accurate navigation requires comparing headings, numbering conventions, logical page labels and source-page evidence.
The useful pipeline is preserve the PDF → locate its printed contents pages → OCR entries, indentation and page references → identify document page labels and existing bookmarks → search for corresponding heading text in the body → reconcile printed and physical page positions → validate links and exceptions → write a reviewable navigation outline. AI helps match imperfect scanned text, but it should not invent pages or quietly send students to a convenient-looking chapter.
The five-question quick route
- Which pages are the printed contents?
- What are the original title, printed number and hierarchy?
- Where is the true matching heading in the scanned document?
- Do file page, label and navigation target agree?
- Have missing, duplicated and out-of-order pages been reviewed?
1. Why a PDF viewer page and a book page can disagree
A PDF is a sequence of page objects. A book may contain a cover, title page, publishing information, foreword and several introductions before its first Arabic-numbered chapter page. The viewer’s first file page can therefore be unrelated to printed page one.
Imagine a book whose physical PDF page 12 carries the printed label 1. The table of contents entry for page 57 might lead to file page 68 under a simple offset. But that calculation is safe only if every preceding page is present and the numbering follows that exact pattern.
A navigation system should distinguish file position from printed page label and from a bookmark destination. Those are separate fields representing different aspects of the same document.
2. Logical and physical page numbers
A logical page number is the label the book assigns to a page, such as vii or 57. A physical page number or file position identifies where the page occurs in the scanned PDF. The two can correspond by an offset but need not.
Research on table-of-contents recognition explicitly distinguishes logical page numbers from physical page numbers and explains why converting between them can be difficult when source page-number printing is inconsistent.
A robust output stores both: printed label 57, actual document page index and the verified heading. This gives a reviewer enough information to understand why a link opens a particular PDF page.
3. Detecting the contents pages
A printed contents page often contains chapter titles, dot leaders, aligned page numbers and indentation. These visual conventions provide clues that distinguish it from an ordinary paragraph page.
A parser can search likely front-matter regions for repeated title-and-page-number patterns. But some books place the contents near the end, and not every list of numbers is a contents page. An exercise index or bibliography can have similar rows.
The detector should keep its candidate page coordinates and allow a human to confirm the contents region before generating navigation for hundreds of entries.
4. OCR the entries without losing their structure
Optical character recognition may read ‘Chapter 4 Energy 57’ as one line, or split the heading and page number into separate blocks. Dot leaders can create false punctuation and interfere with the recognition of small digits.
The program must reconstruct each entry’s title, printed page reference and hierarchy level from the layout. It should distinguish ‘4.2 Energy Transfer — 64’ from two independent entries merely because the title wrapped onto a second line.
An incorrect digit in the contents page can lead to a convincing but wrong link. A source crop lets the reviewer check whether the printed reference was truly 57 or an OCR error such as 51.
5. Indentation encodes chapter hierarchy
A contents page can indent subsections beneath chapters. That indentation expresses parent-child relationships: Energy Transfer may belong within Energy, and Energy in turn belongs within a larger unit.
A layout parser can use left-edge coordinates and numbering schemes to recover hierarchy. If it simply reads every line as a top-level chapter, a navigation outline may become long and confusing, even when its page links are otherwise correct.
Textbook-heading extraction and table-of-contents page matching are related but distinct. One reconstructs heading depth; the other verifies where a specific entry leads.
6. Roman-numbered front matter
Books may number introductory pages i, ii, iii, iv, while the main text restarts at 1. A digital PDF can also contain unnumbered pages before or between these sections.
A single rule such as ‘add ten to the printed page’ may work for the main chapters but fail for Roman-numbered introductions. The same physical sequence can therefore require more than one page-label mapping.
Good software represents numbering ranges explicitly. When the scheme changes, it should identify the transition rather than assume that page labels continue as one uninterrupted Arabic sequence.
7. A complete fictional science textbook example
Imagine a scanned book with a cover, title pages and eight Roman-numbered pages of front matter. The first printed Arabic page, labelled 1, occurs at file position 13 in the editor’s one-based display. The contents list ‘Chapter 3: Photosynthesis — 47’.
A naïve link to PDF viewer page 47 opens a different section. A candidate offset suggests file page 59, but the software checks the actual heading before approving it. It finds the printed chapter opening and stores that confirmed destination.
Now imagine one scan was omitted from the middle. A constant offset that worked for earlier chapters becomes wrong after the gap. The model must detect the mismatch and search the document rather than silently continue the old calculation. This is a fictional textbook.
8. Why title matching is often stronger than offsets
A contents entry supplies words such as ‘Chapter 3: Photosynthesis’. A full-document OCR index can search for that heading in actual page images. The matched heading may provide stronger evidence of the destination than arithmetic on an uncertain offset.
The search should consider context: a chapter title may also occur in a running page header, a bibliography or an earlier contents entry. The desired destination is usually the actual chapter opening, not the first occurrence of that phrase anywhere in the PDF.
A layout-aware title match can inspect font size, surrounding whitespace, page position and neighbouring section text to distinguish an opening heading from a repeated mention.
9. Near-matching OCR is useful but risky
Scanned headings can contain OCR mistakes. One page might recognise ‘Photosynthesis’ correctly while another returns a word with a missing letter. Fuzzy text matching can retrieve plausible candidates despite such differences.
However, fuzzy scores alone may prefer a repeated header over the true chapter start, or confuse ‘Photosynthesis’ with a similar subsection title. The system must combine text resemblance with the page location and heading role.
A high similarity score is a search clue, not a proof of correct navigation. Review candidates that are close in rank or inconsistent with the declared chapter sequence.
10. Physical page labels can come from the PDF
A PDF can store page-label definitions separately from the words printed in its page images. A viewer may display Roman numerals for some pages and Arabic numbers for later ranges when these definitions are present and correct.
PyMuPDF documents functions such as get_page_labels and get_page_numbers, which can retrieve page-label definitions and locate file pages with specified labels. This structured source information can simplify mapping for born-digital or carefully prepared PDFs.
But a newly scanned document may lack those labels, and imported labels can be wrong after editing. The software should verify them against the actual pages instead of treating existing metadata as infallible.
11. Bookmarks are not the same as printed contents
A PDF bookmark is a navigation object that can point to a page or position. A printed contents page is part of the visible document. A scan can contain the latter without any bookmarks.
PyMuPDF’s get_toc and set_toc operations work with PDF outline entries containing hierarchy level, title and target page. A document can therefore gain digital navigation without changing the visible printed table of contents.
These are distinct artifacts. Creating bookmarks does not rewrite the author’s printed page numbers; changing the visible table of contents would be a different, editorial modification.
12. Source page numbers may be missing
Some scanned pages have no visible printed page number because they contain illustrations, title pages or full-page diagrams. In a textbook, a chapter opening might omit its page label even when ordinary chapter pages are numbered.
A model cannot rely exclusively on OCR of footer numbers. It should use verified neighbouring pages and chapter-title matches, while recording uncertainty about the printed label where necessary.
Missing visual labels are an absence of evidence, not confirmation that the page has no place in the numbering sequence.
| Reference type | Example | What it identifies |
|---|---|---|
| PDF file position | Page 59 of scanned file | Position in file sequence |
| Printed page number | 57 | Number shown in original book |
| Roman front-matter label | vii | Logical introduction page |
| Digital PDF bookmark | Chapter Energy → file page 59 | Navigation destination |
| Source heading location | Chapter title on file page 59 | Content-based verification |
13. Repeated running headers can fool title search
A book may print the chapter title at the top of every page. A search for ‘Energy’ can return dozens of pages from the same chapter, all with plausible-looking headings.
A navigation matcher should prefer source blocks classified as chapter-opening headings rather than running page furniture. Repetition patterns, position and the printed contents sequence can support that distinction.
If two pages remain equally plausible, the result can retain candidate destinations for review. Automatically selecting the first occurrence may send students to a running header rather than to the chapter’s true start.
14. Detecting a page missing from the scan
An omitted scan can cause a jump in printed page numbers or a mismatch between expected and observed sections. A contents entry may point to a page whose heading simply does not appear in the PDF.
A safe tool marks the entry as unresolved and warns about possible missing source pages. It should not link to the next vaguely related chapter or generate a synthetic page to make the contents appear complete.
The missing-page analysis should remain distinct from the table-of-contents extraction. The first asks whether the source is complete; the second asks how entries match the pages that actually exist.
15. Duplicated scans can create multiple matches
A scanned book can accidentally contain the same physical paper page twice. The chapter heading may then appear at two different file positions with nearly identical images and text.
An automated matcher needs a policy for such duplicates, ideally preserving the full raw file while identifying that the two candidates may represent one original page. It should not silently remove one copy during navigation construction.
Creating a bookmark to the preferred source copy can be useful, but the report should disclose the other occurrence and any implications for later offsets.
16. Out-of-order pages defeat simple arithmetic
If a scanner batch was assembled in the wrong order, printed page 57 may appear before printed page 49 in the PDF. A fixed offset cannot capture this. The title still may be found correctly through content-based searching.
Before rewriting the document, flag the ordering anomaly and preserve the original scan sequence. Reordering source pages is a separate, potentially consequential editing decision.
A table-of-contents matching algorithm should not claim that all pages are in their intended order merely because its bookmark links open plausible destinations.
17. Multi-line and wrapped contents entries
A long title may take two visual lines, with its page number printed only at the end. OCR may interpret the continuation as a new entry, especially if it begins with a capital letter or has similar indentation.
Layout rules can group line fragments based on spacing, shared indentation and nearby page-number placement. A language model may help recover a plausible combined heading, but must not invent missing words.
Preserve the exact visible title and offer an optional shortened display name separately. The bookmark should remain traceable to the author’s text.
18. Page-number OCR needs its own validation
Small footer numerals are easy to confuse with illustration labels, exercise numbers or stains. A printed 67 might be read as 61, and a Roman numeral vii might be mistaken for letters from nearby text.
Cross-page continuity can provide a useful check. If verified labels before and after a page are 66 and 68, a candidate reading of 67 becomes plausible. But page inserts, skipped numbers and missing scans can break that pattern.
The tool should mark which digits were visually read and which were inferred from sequence. A plausible number is not the same as an independently legible printed label.
19. Matching must respect document sections
A book may contain a chapter called ‘Introduction’ and later an appendix section with a similar heading. A global fuzzy search could point a contents entry to the wrong one.
Use local constraints such as expected sequence and neighbouring verified entries, then compare heading roles and surrounding text. Those constraints should help rank candidates but not override an actual source mismatch.
When the evidence conflicts, keep the entry unresolved for manual review. A wrong confident bookmark is less helpful than an explicit warning that the destination needs checking.
| Condition | Risk | Safer response |
|---|---|---|
| Unnumbered front matter | Constant offset mistaken | Map numbering transition |
| One scan missing | All later links shifted | Find actual headings |
| Duplicate page scan | Multiple candidate destinations | Flag duplicate |
| Running header repeats title | Wrong title match | Use section-opening role |
| OCR reads 57 as 51 | Incorrect printed reference | Inspect page crop |
| Zero/one indexing confusion | Link opens adjacent page | Test destination convention |
| No chapter found | Fabricated navigation | Leave unresolved |
20. The one-based and zero-based problem
Software libraries commonly number internal page arrays from zero, while readers usually see page one as the first displayed page. Some PDF outline APIs expect one-based page numbers, adding another place where off-by-one errors can occur.
PyMuPDF documents these conventions explicitly: its get_toc result uses one-based page numbers for human-readable outline entries, while other page operations can use zero-based indices.
A robust pipeline converts indices deliberately and tests the first, middle and last navigation targets. A completely correct chapter match can still open the wrong page if the implementation mixes these conventions.
21. Building hyperlinks and bookmarks safely
After verifying an entry’s destination, a program can create a PDF outline or hyperlink that opens the appropriate page. The entry title, depth and target are stored as structured data rather than guessed from the printed page reference at playback time.
PyMuPDF’s set_toc documentation explains the required level-title-page representation and its handling of destination pages. A practical publisher should save a derivative PDF rather than modify the only original scan.
Before distributing the result, open every critical destination or perform automated link checks with manual sampling. Unverified links should be marked as pending rather than published as though the entire book has been mapped perfectly.
22. A simple paper exercise
Create a fictional booklet with two unnumbered front pages followed by printed pages one through six. Write a contents list pointing to chapters on printed pages one, three and five. Shuffle one physical sheet before photographing all pages.
Ask students to record each file position and visible page label. A constant offset works until the shuffled page disrupts the pattern. Then match the chapter headings themselves and discuss which pieces of evidence are more reliable.
This illustrates the difference between a physical page, printed label and navigation destination without requiring any copyrighted textbook scan or complex software.
23. How to evaluate a contents-page matcher
Build a test set containing scanned books with verified links, Roman-numbered front matter, repeated headings, missing pages, duplicates, varied column layouts and OCR errors. Evaluate whether the model finds the correct contents region, reads its entries and points them to the intended destinations.
Report destination accuracy separately from title OCR and hierarchy detection. A parser might recognise every entry while sending all links one page late. Another could place links correctly but flatten the chapter structure.
A final reader test matters: can a learner select ‘Photosynthesis’ and reach its actual opening without searching manually? That practical outcome is more meaningful than a single overall text similarity score.
24. Preserve original pagination for citations
Changing the sequence of file pages or reprinting page numbers can affect readers who refer to the original edition by its printed labels. A navigation-enhanced derivative should preserve those visible citations when possible.
The tool can store a mapping from printed labels to file positions without rewriting the book itself. If the source contains errors or omissions, the audit report should describe them rather than silently standardise them away.
That distinction matters for school reading assignments and academic references. Good navigation makes source pages easier to find while leaving their original identity intact.
25. The bigger lesson: links require verified relationships
Table-of-contents matching is a useful example of AI connecting document-level evidence. OCR recovers titles and printed numbers, layout models recover hierarchy, and source searches identify where chapters actually appear.
These clues can conflict, especially in scanned books with missing, duplicated or re-ordered pages. A trustworthy pipeline records the chosen target and why it was accepted, allowing users to inspect the original.
The durable principle is not to confuse a plausible printed reference with a verified file position. AI should make learning books easier to navigate without inventing pages or silently changing what page numbers mean.
Frequently asked questions
Why does PDF page 57 not match printed page 57?
The file may include covers or Roman-numbered front matter before its printed Arabic pages.
What is the difference between logical and physical page numbers?
Logical numbers are printed or declared labels; physical positions locate pages within the scanned file.
Can OCR alone make a clickable table of contents?
No. It must also find and verify the corresponding destinations.
What if a scan contains missing pages?
The system should flag unresolved entries rather than invent pages or use one offset blindly.
How can AI match a chapter title despite OCR errors?
Fuzzy text retrieval combined with heading layout and sequence evidence can identify candidates.
What are PDF page labels?
Metadata that may define display labels such as Roman numerals and Arabic numbers for page ranges.
Can PyMuPDF create PDF bookmarks?
Yes. Its set_toc method accepts hierarchy level, title and target page information.
Why can running headers cause errors?
Repeated chapter names can appear on many pages without marking new chapter openings.
How can one-based indexing cause trouble?
A library may use one-based outline targets while internal page arrays are zero-based.
What should a navigation audit contain?
Original entry, printed label, verified PDF position, source heading and review status.
Primary technical references and connected lessons
- PyMuPDF: Document TOC, Bookmarks and Page Labels
- PyMuPDF: Tutorial on PDF Outlines and Bookmarks
- PyMuPDF: Page Indexing and Navigation Basics
- toc-this: TOC Extraction and OCR-Based Matching for Scanned PDFs
- How AI Builds a Heading Outline From Scanned Textbooks
- How AI Finds Missing and Out-of-Order Pages in Scanned Documents
- How AI Finds the Correct Reading Order on a Scanned Page
- eduKateSG | How X Works Hub
Editorial note: The chapter titles, page numbers and scanned textbook examples are fictional illustrations. A printed contents entry and a PDF page index are distinct records. OCR, fuzzy matching and offset rules cannot guarantee complete scans or correct links; preserve the raw source, verify destinations and disclose unresolved cases.