A Windows-ready Python workflow for converting a directory of PDF books into simple Markdown with OCR fallback, table extraction, figure extraction, metadata detection, and master index files.
This project scans a folder of PDF books and attempts to:
- detect title, author, and ISBN from the first 10 pages
- apply a consistent naming convention
- convert each book into simple Markdown
- use OCR on low-text or scanned pages
- extract tables into CSV files
- extract figures/images into PNG files
- guess figure and table captions from page text
- create a per-book
manifest.json - create a master
index.csv - create a master
index.md - log failures into
failures.json
This works best for:
- digital PDFs with selectable text
- mixed PDFs where some pages are scanned
- building a searchable working archive of books
This is less reliable for:
- heavily scanned books with poor image quality
- complex multi-column layouts
- highly formatted textbooks with complicated tables
- pages where captions are far away from figures
Each book gets a stable folder name.
isbn_<isbn>
Example:
isbn_9780323445481
<author_slug>__<title_slug>
Example:
wyatt_crosby__crazy_busy_doctor
output/
index.csv
index.md
failures.json
isbn_9781234567890/
isbn_9781234567890.md
manifest.json
assets/
tables/
page_0005_table_01.csv
figures/
page_0007_img_01.png
Follow these steps exactly. You only need to do this once.
-
Download Python 3.11 or newer
-
During installation, check this box:
Add Python to PATH
- After installing, open PowerShell and verify:
python --versionExpected output:
Python 3.11.x
- Download Tesseract OCR for Windows.
- Install it using default settings.
Default install location:
C:\Program Files\Tesseract-OCR\tesseract.exe
You may need this path later.
Open PowerShell:
mkdir pdf-book-md-converter
cd pdf-book-md-converterCreate a file named:
convert_books.py
Paste the full Python script into this file.
python -m venv .venv.venv\Scripts\Activate.ps1If you get a permission error, run:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
.venv\Scripts\Activate.ps1pip install pymupdf pdfplumber pandas openpyxl pillow pytesseractBasic run:
python convert_books.py --input "D:\books" --output "D:\books_md"If Tesseract is not detected:
python convert_books.py --input "D:\books" --output "D:\books_md" --tesseract-cmd "C:\Program Files\Tesseract-OCR\tesseract.exe"For each PDF:
- scans first 10 pages
- detects:
- title
- author
- ISBN
- creates a consistent folder name
- extracts text
- uses OCR if needed
- removes repeated headers/footers
- converts text to Markdown
- extracts:
- tables to CSV
- images to PNG
- detects captions
- saves:
- markdown file
- manifest.json
Then creates:
- index.csv
- index.md
- failures.json
- saved as CSV
- linked in Markdown
- not flattened into messy text
- saved as PNG
- embedded in Markdown
- captions included when detected
python convert_books.py --input "D:\medical_books" --output "D:\md_books" --tesseract-cmd "C:\Program Files\Tesseract-OCR\tesseract.exe"Only run:
.venv\Scripts\Activate.ps1
python convert_books.py --input "D:\books" --output "D:\books_md"Expect weaker results for:
- scanned low-quality PDFs
- complex tables
- multi-column layouts
- distant captions
- poor metadata
Use this for:
- building a clean archive
- creating searchable datasets
- preprocessing for AI
Not for:
- perfect formatting reproduction
pdf-book-md-converter