When working with large PDF documents (research papers, reports, books, manuals), extracting the table of contents (TOC) or document structure is not always straightforward.
- Many PDFs lack a proper outline/TOC embedded in their metadata.
- Machine learning–based approaches exist, but they can be slow, require training data, and demand heavy dependencies.
- A lightweight, fast, and model-free solution is often more practical.
This project provides a heuristic-based PDF outline extractor that analyzes font size, boldness, and text patterns to detect titles, headings, and subheadings from PDF files.
- No machine learning model needed – purely heuristic rules.
- Very fast – processes a 50-page PDF in ~5 seconds.
- Extracts document title and outline hierarchy (H0, H1, H2).
- Works even when the PDF has no embedded outline/TOC.
- Uses font size, boldness, indentation, and formatting clues to detect headings.
- Supports batch processing (process all PDFs in a folder).
- Saves results as structured JSON files.
The extractor follows a heuristic approach:
- Reads all text spans from the PDF using PyMuPDF (
fitz). - Collects font sizes, bold flags, and bounding boxes.
- Applies rules to detect likely headings based on:
- Larger-than-normal font size
- Bold text usage
- Title case / uppercase / numbering (e.g.,
1. Introduction) - Left margin alignment
- Builds a document title from the largest, topmost headings.
- Constructs an outline hierarchy (H0/H1/H2).
- Saves output as JSON (with
title+outline).{ "title": "Document Title", "outline": [ { "level": "H0", "text": "Introduction", "page": 1 }, { "level": "H1", "text": "Background", "page": 2 }, { "level": "H2", "text": "Previous Work", "page": 3 } ] }
dochive/
├── app/
│ ├── input/ # Place your PDF files here
│ └── output/ # Extracted JSON outlines will be saved here
├── process_pdfs.py # Main extraction script
└── README.md
- Python 3.7 or higher
- pip package manager
pip install PyMuPDF- Place your PDF files in the input/ directory
- Run the script:
python process_pdfs.py - Check the output/ directory for JSON results
You can use Docker to containerize and run the PDF outline extractor easily.
- Build the Docker Image Run this command in the project root (where your Dockerfile and process_pdfs.py are):
docker build -t pdf-outline-extractor .
This builds a Docker image named pdf-outline-extractor using Python 3.10-slim with PyMuPDF installed.
- Run the Container Run the container, mounting your local input and output directories into the container:
docker run --rm \
-v /full/path/to/input:/app/input \
-v /full/path/to/output:/app/output \
pdf-outline-extractor
- Replace /full/path/to/input and /full/path/to/output with your actual directories on your machine.
- Place your PDF files inside the input directory before running.
- The extracted JSON outline files will be saved inside the output directory.
For CMD:
docker run --rm -v C:\full\path\to\input:/app/input -v C:\full\path\to\output:/app/output pdf-outline-extractor
- Verify Output - After running, check the output folder for JSON files corresponding to your processed PDFs.
This project, DocHive, was developed as part of the Adobe Hackathon 1A – Connecting Dots round.
Successfully qualified for the final round with this solution.
This project complies with the official constraints defined for Adobe Hackathon Round 1A:
| Constraint Type | Requirement |
|---|---|
| Execution Time | ≤ 10 seconds for a 50-page PDF |
| Model Size | ≤ 200 MB (if any used) |
| Network | No internet access allowed |
| Runtime | Must run on CPU only (amd64) |
| System Config | Tested on 8 CPUs, 16 GB RAM setup |