pdf-toc-generator 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sameer Bajaj
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,309 @@
1
+ Metadata-Version: 2.4
2
+ Name: pdf-toc-generator
3
+ Version: 1.0.0
4
+ Summary: Automatically generate and add bookmarks to PDF files
5
+ Author-email: Sameer Bajaj <sameer@sameerbajaj.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://sameerbajaj.com/tools/pdf-toc/
8
+ Project-URL: Website, https://sameerbajaj.com
9
+ Project-URL: Repository, https://github.com/sameerbajaj/pdf_toc_generator
10
+ Keywords: pdf,table-of-contents,bookmarks,toc,pymupdf
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: pymupdf>=1.23.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: jupyter>=1.0.0; extra == "dev"
25
+ Requires-Dist: ipykernel>=6.25.0; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # PDF Table of Contents Generator
29
+
30
+ Automatically generate and add bookmarks (table of contents) to PDF files. Supports two methods:
31
+ 1. **Extract from existing TOC page** - Intelligently detects and extracts from built-in TOC pages
32
+ 2. **Font-based detection** - Analyzes text formatting to identify heading hierarchy
33
+
34
+ ## Features
35
+
36
+ - 🔖 Automatically adds clickable bookmarks to PDFs
37
+ - 📄 Detects and extracts from existing TOC pages
38
+ - 🎯 Smart matching of TOC entries to document pages
39
+ - 🎛️ Multiple structure options (hierarchical or flat)
40
+ - ⚡ One-line installation and execution
41
+ - 🖥️ Interactive mode with guided prompts
42
+ - 🐍 Pure Python with minimal dependencies
43
+
44
+ ## Quick Start
45
+
46
+ ### One-Line Execution (with UV)
47
+
48
+ ```bash
49
+ uvx --from git+https://github.com/sameerbajaj/pdf_toc_generator pdf_toc_generator
50
+ ```
51
+
52
+ This will:
53
+ 1. Install the tool automatically
54
+ 2. Run in interactive mode
55
+ 3. Guide you through the process with prompts
56
+
57
+ ### Installation
58
+
59
+ #### Using UV (Recommended)
60
+
61
+ ```bash
62
+ # Install UV if you haven't already
63
+ curl -LsSf https://astral.sh/uv/install.sh | sh
64
+
65
+ # Run the tool directly (no installation needed)
66
+ uvx --from git+https://github.com/sameerbajaj/pdf_toc_generator pdf_toc_generator
67
+ ```
68
+
69
+ #### Manual Installation
70
+
71
+ ```bash
72
+ git clone https://github.com/sameerbajaj/pdf_toc_generator.git
73
+ cd pdf_toc_generator
74
+ uv sync
75
+ uv run pdf_toc_generator.py
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ ### Interactive Mode (Recommended for First-Time Users)
81
+
82
+ Simply run without arguments to enter interactive mode:
83
+
84
+ ```bash
85
+ uv run pdf_toc_generator.py
86
+ ```
87
+
88
+ You'll be prompted for:
89
+ - PDF file path
90
+ - Output file path (optional, defaults to `input_with_toc.pdf`)
91
+ - Whether to extract from existing TOC page (y/n)
92
+ - Whether to use flat structure (y/n)
93
+ - Whether to add "Table of Contents" bookmark (y/n)
94
+
95
+ ### Command-Line Arguments
96
+
97
+ ```bash
98
+ # Basic usage
99
+ uv run pdf_toc_generator.py input.pdf
100
+
101
+ # Specify output file
102
+ uv run pdf_toc_generator.py input.pdf -o output.pdf
103
+
104
+ # Create flat structure (no hierarchy)
105
+ uv run pdf_toc_generator.py input.pdf --flat
106
+
107
+ # Skip existing TOC page detection (use font-based method)
108
+ uv run pdf_toc_generator.py input.pdf --no-existing-toc
109
+
110
+ # Don't add "Table of Contents" bookmark
111
+ uv run pdf_toc_generator.py input.pdf --no-toc-bookmark
112
+
113
+ # Use OCR mode for poorly scanned PDFs
114
+ uv run pdf_toc_generator.py scanned_document.pdf --ocr-mode
115
+
116
+ # Combine options
117
+ uv run pdf_toc_generator.py input.pdf -o output.pdf --flat --ocr-mode
118
+ ```
119
+
120
+ ### Help
121
+
122
+ ```bash
123
+ uv run pdf_toc_generator.py --help
124
+ ```
125
+
126
+ ## Examples
127
+
128
+ ### Example 1: Book with Existing TOC
129
+ ```bash
130
+ $ uv run pdf_toc_generator.py book.pdf
131
+
132
+ ================================================================================
133
+ PDF TABLE OF CONTENTS GENERATOR
134
+ ================================================================================
135
+
136
+ Processing: book.pdf
137
+
138
+ Step 1: Checking for existing TOC page...
139
+ ✓ Found TOC spanning pages 2-5
140
+
141
+ Step 2: Extracting TOC from dedicated page...
142
+ ✓ Extracted 174 entries from TOC page
143
+ ...
144
+ ✓ COMPLETE! (Method: existing_toc)
145
+ ```
146
+
147
+ ### Example 2: Technical Document (Font-Based)
148
+ ```bash
149
+ $ uv run pdf_toc_generator.py document.pdf --no-existing-toc
150
+
151
+ Processing: document.pdf
152
+
153
+ Step 1: Extracting text with formatting...
154
+ Extracted 1234 text blocks from 50 pages
155
+
156
+ Step 2: Analyzing font statistics...
157
+ Body text size (most common): 12.0
158
+ ...
159
+ ✓ COMPLETE! (Method: font_detection)
160
+ ```
161
+
162
+ ### Example 3: Flat Structure
163
+ ```bash
164
+ $ uv run pdf_toc_generator.py report.pdf --flat -o report_bookmarks.pdf
165
+
166
+ ✓ Converting to flat structure (all entries at level 1)
167
+ ✓ Added 45 bookmarks to PDF
168
+ ```
169
+
170
+ ### Example 4: OCR Mode (Poorly Scanned PDFs)
171
+ ```bash
172
+ $ uv run pdf_toc_generator.py scanned_book.pdf --ocr-mode
173
+
174
+ Step 2: Extracting TOC from dedicated page...
175
+ (OCR mode enabled - will use enhanced extraction for poor quality scans)
176
+ Found 25 potential titles and 25 page numbers
177
+ ⚠ Warning: 20/25 page numbers exceed PDF page count (15)
178
+ This appears to be an excerpt or the TOC references the original document's page numbers.
179
+ Will use fuzzy matching to find headings in the available pages.
180
+ ✓ Matched 25 entries using OCR-style extraction
181
+ ...
182
+ ✓ COMPLETE! (Method: existing_toc)
183
+ ```
184
+
185
+ ## How It Works
186
+
187
+ ### Method 1: Existing TOC Page (Primary)
188
+
189
+ 1. **Detects** TOC pages by looking for "Table of Contents", "Contents", or multiple chapter references
190
+ 2. **Extracts** entries with page numbers, preserving hierarchy based on indentation and font size
191
+ - **Standard extraction**: Expects title and page number on the same line (e.g., "Chapter 1 ... 15")
192
+ - **OCR mode** (use `--ocr-mode`): Handles poorly scanned PDFs where titles and page numbers are on separate lines
193
+ 3. **Validates** extracted page numbers against PDF page count (warns if out of range for excerpts)
194
+ 4. **Matches** TOC entries to actual document locations using fuzzy text matching (excludes TOC pages from search)
195
+ 5. **Creates** bookmarks that mirror the original TOC structure
196
+
197
+ ### Method 2: Font-Based Detection (Fallback)
198
+
199
+ 1. **Extracts** all text with font metadata (size, style, position)
200
+ 2. **Analyzes** font size distribution to identify body text vs headings
201
+ 3. **Classifies** headings by hierarchy level based on font size
202
+ 4. **Generates** TOC structure with proper nesting
203
+
204
+ ## Options Explained
205
+
206
+ ### `--flat`
207
+ Creates a flat bookmark structure where all entries are at level 1 (no indentation/hierarchy).
208
+
209
+ **Without `--flat` (hierarchical):**
210
+ ```
211
+ ▪ Chapter 1
212
+ • Section 1.1
213
+ • Subsection 1.1.1
214
+ ▪ Chapter 2
215
+ ```
216
+
217
+ **With `--flat`:**
218
+ ```
219
+ ▪ Chapter 1
220
+ ▪ Section 1.1
221
+ ▪ Subsection 1.1.1
222
+ ▪ Chapter 2
223
+ ```
224
+
225
+ ### `--no-existing-toc`
226
+ Forces the tool to use font-based detection instead of trying to extract from an existing TOC page. Useful if the PDF has a TOC page but you want to generate bookmarks based on actual headings.
227
+
228
+ ### `--no-toc-bookmark`
229
+ Prevents adding a "Table of Contents" bookmark that points to the TOC page. Only applies when an existing TOC page is detected.
230
+
231
+ ### `--ocr-mode`
232
+ Enables OCR-tolerant extraction for poorly scanned PDFs. Use this when:
233
+ - The PDF has low quality OCR text
234
+ - Titles and page numbers in the TOC are on separate lines
235
+ - Standard extraction produces garbage bookmarks or fails
236
+
237
+ **What it does:**
238
+ - Collects all text lines from TOC pages
239
+ - Separates titles from page numbers
240
+ - Combines fragmented section headers (e.g., "PART", "ONE" → "PART ONE")
241
+ - Validates page numbers against PDF page count
242
+ - Uses full-document fuzzy matching for out-of-range pages (common with excerpts)
243
+ - **Validates matches**: Only includes bookmarks with match score > 0.85 (skips TOC entries not found in document)
244
+
245
+ **When to use:**
246
+ - Scanned documents with poor OCR quality
247
+ - PDFs where TOC extraction produces individual words as bookmarks
248
+ - Excerpt PDFs where TOC references original document page numbers
249
+
250
+ **Important for excerpts:**
251
+ If your PDF is an excerpt (e.g., 20 pages from a 200-page book), the tool will skip TOC entries for missing chapters. This is expected behavior and ensures bookmarks only point to content that actually exists in your PDF.
252
+
253
+ ## Requirements
254
+
255
+ - Python 3.8+
256
+ - PyMuPDF (automatically installed)
257
+
258
+ ## Development
259
+
260
+ ### Using Jupyter Notebook
261
+
262
+ A Jupyter notebook version is included for exploration and customization:
263
+
264
+ ```bash
265
+ uv run jupyter notebook pdf_toc_generator.ipynb
266
+ ```
267
+
268
+ ## Troubleshooting
269
+
270
+ ### "No headings found"
271
+ - Try adjusting the font size detection threshold
272
+ - Use `--no-existing-toc` to force font-based detection
273
+ - Check if your PDF has selectable text (not scanned images)
274
+
275
+ ### Poor quality bookmarks (individual words like "THE", "MINTO", etc.)
276
+ - Your PDF likely has poor OCR quality
277
+ - Use `--ocr-mode` flag to enable enhanced extraction
278
+ - In interactive mode, answer "yes" to "Is this a poorly scanned/OCR'd PDF?"
279
+
280
+ ### TOC page numbers don't match document (e.g., TOC says page 45 but PDF only has 20 pages)
281
+ - This is normal for excerpt PDFs or scanned partial documents
282
+ - The tool automatically uses fuzzy matching to find headings in available pages
283
+ - Use `--ocr-mode` for better results with excerpts
284
+
285
+ ### "File not found"
286
+ - Verify the PDF path is correct
287
+ - Use absolute paths or ensure you're in the correct directory
288
+ - Check file permissions
289
+
290
+ ### Bookmarks not visible in PDF viewer
291
+ - Try a different PDF viewer (Adobe Acrobat, Preview, Chrome)
292
+ - Look for a bookmarks/outline panel (usually on the left sidebar)
293
+ - Some nested bookmarks may be collapsed - click the expand arrow
294
+
295
+ ## License
296
+
297
+ MIT License - see LICENSE file for details
298
+
299
+ ## Contributing
300
+
301
+ Contributions are welcome! Please feel free to submit a Pull Request.
302
+
303
+ ## Acknowledgments
304
+
305
+ Built with [PyMuPDF](https://pymupdf.readthedocs.io/) for PDF processing.
306
+
307
+ ---
308
+
309
+ Part of the open-source tools collection by [Sameer Bajaj](https://sameerbajaj.com). Learn more on the [project page](https://sameerbajaj.com/tools/pdf-toc/).
@@ -0,0 +1,282 @@
1
+ # PDF Table of Contents Generator
2
+
3
+ Automatically generate and add bookmarks (table of contents) to PDF files. Supports two methods:
4
+ 1. **Extract from existing TOC page** - Intelligently detects and extracts from built-in TOC pages
5
+ 2. **Font-based detection** - Analyzes text formatting to identify heading hierarchy
6
+
7
+ ## Features
8
+
9
+ - 🔖 Automatically adds clickable bookmarks to PDFs
10
+ - 📄 Detects and extracts from existing TOC pages
11
+ - 🎯 Smart matching of TOC entries to document pages
12
+ - 🎛️ Multiple structure options (hierarchical or flat)
13
+ - ⚡ One-line installation and execution
14
+ - 🖥️ Interactive mode with guided prompts
15
+ - 🐍 Pure Python with minimal dependencies
16
+
17
+ ## Quick Start
18
+
19
+ ### One-Line Execution (with UV)
20
+
21
+ ```bash
22
+ uvx --from git+https://github.com/sameerbajaj/pdf_toc_generator pdf_toc_generator
23
+ ```
24
+
25
+ This will:
26
+ 1. Install the tool automatically
27
+ 2. Run in interactive mode
28
+ 3. Guide you through the process with prompts
29
+
30
+ ### Installation
31
+
32
+ #### Using UV (Recommended)
33
+
34
+ ```bash
35
+ # Install UV if you haven't already
36
+ curl -LsSf https://astral.sh/uv/install.sh | sh
37
+
38
+ # Run the tool directly (no installation needed)
39
+ uvx --from git+https://github.com/sameerbajaj/pdf_toc_generator pdf_toc_generator
40
+ ```
41
+
42
+ #### Manual Installation
43
+
44
+ ```bash
45
+ git clone https://github.com/sameerbajaj/pdf_toc_generator.git
46
+ cd pdf_toc_generator
47
+ uv sync
48
+ uv run pdf_toc_generator.py
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ ### Interactive Mode (Recommended for First-Time Users)
54
+
55
+ Simply run without arguments to enter interactive mode:
56
+
57
+ ```bash
58
+ uv run pdf_toc_generator.py
59
+ ```
60
+
61
+ You'll be prompted for:
62
+ - PDF file path
63
+ - Output file path (optional, defaults to `input_with_toc.pdf`)
64
+ - Whether to extract from existing TOC page (y/n)
65
+ - Whether to use flat structure (y/n)
66
+ - Whether to add "Table of Contents" bookmark (y/n)
67
+
68
+ ### Command-Line Arguments
69
+
70
+ ```bash
71
+ # Basic usage
72
+ uv run pdf_toc_generator.py input.pdf
73
+
74
+ # Specify output file
75
+ uv run pdf_toc_generator.py input.pdf -o output.pdf
76
+
77
+ # Create flat structure (no hierarchy)
78
+ uv run pdf_toc_generator.py input.pdf --flat
79
+
80
+ # Skip existing TOC page detection (use font-based method)
81
+ uv run pdf_toc_generator.py input.pdf --no-existing-toc
82
+
83
+ # Don't add "Table of Contents" bookmark
84
+ uv run pdf_toc_generator.py input.pdf --no-toc-bookmark
85
+
86
+ # Use OCR mode for poorly scanned PDFs
87
+ uv run pdf_toc_generator.py scanned_document.pdf --ocr-mode
88
+
89
+ # Combine options
90
+ uv run pdf_toc_generator.py input.pdf -o output.pdf --flat --ocr-mode
91
+ ```
92
+
93
+ ### Help
94
+
95
+ ```bash
96
+ uv run pdf_toc_generator.py --help
97
+ ```
98
+
99
+ ## Examples
100
+
101
+ ### Example 1: Book with Existing TOC
102
+ ```bash
103
+ $ uv run pdf_toc_generator.py book.pdf
104
+
105
+ ================================================================================
106
+ PDF TABLE OF CONTENTS GENERATOR
107
+ ================================================================================
108
+
109
+ Processing: book.pdf
110
+
111
+ Step 1: Checking for existing TOC page...
112
+ ✓ Found TOC spanning pages 2-5
113
+
114
+ Step 2: Extracting TOC from dedicated page...
115
+ ✓ Extracted 174 entries from TOC page
116
+ ...
117
+ ✓ COMPLETE! (Method: existing_toc)
118
+ ```
119
+
120
+ ### Example 2: Technical Document (Font-Based)
121
+ ```bash
122
+ $ uv run pdf_toc_generator.py document.pdf --no-existing-toc
123
+
124
+ Processing: document.pdf
125
+
126
+ Step 1: Extracting text with formatting...
127
+ Extracted 1234 text blocks from 50 pages
128
+
129
+ Step 2: Analyzing font statistics...
130
+ Body text size (most common): 12.0
131
+ ...
132
+ ✓ COMPLETE! (Method: font_detection)
133
+ ```
134
+
135
+ ### Example 3: Flat Structure
136
+ ```bash
137
+ $ uv run pdf_toc_generator.py report.pdf --flat -o report_bookmarks.pdf
138
+
139
+ ✓ Converting to flat structure (all entries at level 1)
140
+ ✓ Added 45 bookmarks to PDF
141
+ ```
142
+
143
+ ### Example 4: OCR Mode (Poorly Scanned PDFs)
144
+ ```bash
145
+ $ uv run pdf_toc_generator.py scanned_book.pdf --ocr-mode
146
+
147
+ Step 2: Extracting TOC from dedicated page...
148
+ (OCR mode enabled - will use enhanced extraction for poor quality scans)
149
+ Found 25 potential titles and 25 page numbers
150
+ ⚠ Warning: 20/25 page numbers exceed PDF page count (15)
151
+ This appears to be an excerpt or the TOC references the original document's page numbers.
152
+ Will use fuzzy matching to find headings in the available pages.
153
+ ✓ Matched 25 entries using OCR-style extraction
154
+ ...
155
+ ✓ COMPLETE! (Method: existing_toc)
156
+ ```
157
+
158
+ ## How It Works
159
+
160
+ ### Method 1: Existing TOC Page (Primary)
161
+
162
+ 1. **Detects** TOC pages by looking for "Table of Contents", "Contents", or multiple chapter references
163
+ 2. **Extracts** entries with page numbers, preserving hierarchy based on indentation and font size
164
+ - **Standard extraction**: Expects title and page number on the same line (e.g., "Chapter 1 ... 15")
165
+ - **OCR mode** (use `--ocr-mode`): Handles poorly scanned PDFs where titles and page numbers are on separate lines
166
+ 3. **Validates** extracted page numbers against PDF page count (warns if out of range for excerpts)
167
+ 4. **Matches** TOC entries to actual document locations using fuzzy text matching (excludes TOC pages from search)
168
+ 5. **Creates** bookmarks that mirror the original TOC structure
169
+
170
+ ### Method 2: Font-Based Detection (Fallback)
171
+
172
+ 1. **Extracts** all text with font metadata (size, style, position)
173
+ 2. **Analyzes** font size distribution to identify body text vs headings
174
+ 3. **Classifies** headings by hierarchy level based on font size
175
+ 4. **Generates** TOC structure with proper nesting
176
+
177
+ ## Options Explained
178
+
179
+ ### `--flat`
180
+ Creates a flat bookmark structure where all entries are at level 1 (no indentation/hierarchy).
181
+
182
+ **Without `--flat` (hierarchical):**
183
+ ```
184
+ ▪ Chapter 1
185
+ • Section 1.1
186
+ • Subsection 1.1.1
187
+ ▪ Chapter 2
188
+ ```
189
+
190
+ **With `--flat`:**
191
+ ```
192
+ ▪ Chapter 1
193
+ ▪ Section 1.1
194
+ ▪ Subsection 1.1.1
195
+ ▪ Chapter 2
196
+ ```
197
+
198
+ ### `--no-existing-toc`
199
+ Forces the tool to use font-based detection instead of trying to extract from an existing TOC page. Useful if the PDF has a TOC page but you want to generate bookmarks based on actual headings.
200
+
201
+ ### `--no-toc-bookmark`
202
+ Prevents adding a "Table of Contents" bookmark that points to the TOC page. Only applies when an existing TOC page is detected.
203
+
204
+ ### `--ocr-mode`
205
+ Enables OCR-tolerant extraction for poorly scanned PDFs. Use this when:
206
+ - The PDF has low quality OCR text
207
+ - Titles and page numbers in the TOC are on separate lines
208
+ - Standard extraction produces garbage bookmarks or fails
209
+
210
+ **What it does:**
211
+ - Collects all text lines from TOC pages
212
+ - Separates titles from page numbers
213
+ - Combines fragmented section headers (e.g., "PART", "ONE" → "PART ONE")
214
+ - Validates page numbers against PDF page count
215
+ - Uses full-document fuzzy matching for out-of-range pages (common with excerpts)
216
+ - **Validates matches**: Only includes bookmarks with match score > 0.85 (skips TOC entries not found in document)
217
+
218
+ **When to use:**
219
+ - Scanned documents with poor OCR quality
220
+ - PDFs where TOC extraction produces individual words as bookmarks
221
+ - Excerpt PDFs where TOC references original document page numbers
222
+
223
+ **Important for excerpts:**
224
+ If your PDF is an excerpt (e.g., 20 pages from a 200-page book), the tool will skip TOC entries for missing chapters. This is expected behavior and ensures bookmarks only point to content that actually exists in your PDF.
225
+
226
+ ## Requirements
227
+
228
+ - Python 3.8+
229
+ - PyMuPDF (automatically installed)
230
+
231
+ ## Development
232
+
233
+ ### Using Jupyter Notebook
234
+
235
+ A Jupyter notebook version is included for exploration and customization:
236
+
237
+ ```bash
238
+ uv run jupyter notebook pdf_toc_generator.ipynb
239
+ ```
240
+
241
+ ## Troubleshooting
242
+
243
+ ### "No headings found"
244
+ - Try adjusting the font size detection threshold
245
+ - Use `--no-existing-toc` to force font-based detection
246
+ - Check if your PDF has selectable text (not scanned images)
247
+
248
+ ### Poor quality bookmarks (individual words like "THE", "MINTO", etc.)
249
+ - Your PDF likely has poor OCR quality
250
+ - Use `--ocr-mode` flag to enable enhanced extraction
251
+ - In interactive mode, answer "yes" to "Is this a poorly scanned/OCR'd PDF?"
252
+
253
+ ### TOC page numbers don't match document (e.g., TOC says page 45 but PDF only has 20 pages)
254
+ - This is normal for excerpt PDFs or scanned partial documents
255
+ - The tool automatically uses fuzzy matching to find headings in available pages
256
+ - Use `--ocr-mode` for better results with excerpts
257
+
258
+ ### "File not found"
259
+ - Verify the PDF path is correct
260
+ - Use absolute paths or ensure you're in the correct directory
261
+ - Check file permissions
262
+
263
+ ### Bookmarks not visible in PDF viewer
264
+ - Try a different PDF viewer (Adobe Acrobat, Preview, Chrome)
265
+ - Look for a bookmarks/outline panel (usually on the left sidebar)
266
+ - Some nested bookmarks may be collapsed - click the expand arrow
267
+
268
+ ## License
269
+
270
+ MIT License - see LICENSE file for details
271
+
272
+ ## Contributing
273
+
274
+ Contributions are welcome! Please feel free to submit a Pull Request.
275
+
276
+ ## Acknowledgments
277
+
278
+ Built with [PyMuPDF](https://pymupdf.readthedocs.io/) for PDF processing.
279
+
280
+ ---
281
+
282
+ Part of the open-source tools collection by [Sameer Bajaj](https://sameerbajaj.com). Learn more on the [project page](https://sameerbajaj.com/tools/pdf-toc/).