This repository contains the solution for the Adobe India Hackathon.
Our solution for extracting a structured outline (Title, H1, H2, H3) from PDFs is based on a hybrid approach that combines rule-based heuristics with a lightweight machine learning model.
- Text Extraction: We use the
PyMuPDFlibrary to extract text blocks along with their metadata (font size, font name, position on page). - Feature Engineering: For each text block, we extract features like relative font size, capitalization, line position, presence of numbering (e.g., "1.1", "A."), and boldness.
- Classification: A trained classifier (Random Forest) predicts the heading level (H1, H2, H3, or body text) based on these features. The Title is typically identified as the largest text on the first page.
- Multilingual Support (Bonus): We handle Japanese and other languages by using font properties and layout cues that are language-agnostic.
- Libraries:
PyMuPDF,scikit-learn,pandas,numpy - Models: We use a
scikit-learnRandom Forest classifier (ml_classifier.joblib) which is included in the/modelsdirectory. The model size is under 200MB.
The solution is containerized using Docker and is designed to run completely offline on a CPU.
-
Build the Docker Image:
docker build --platform linux/amd64 -t mysolutionname:somerandomidentifier . -
Run the Container: Create
inputandoutputdirectories in your current host directory. Place your test PDFs in theinputfolder.# For Linux/macOS docker run --rm -v $(pwd)/input:/app/input -v $(pwd)/output:/app/output --network none mysolutionname:somerandomidentifier # For Windows (Command Prompt) docker run --rm -v %cd%/input:/app/input -v %cd%/output:/app/output --network none mysolutionname:somerandomidentifier # For Windows (PowerShell) docker run --rm -v ${pwd}/input:/app/input -v ${pwd}/output:/app/output --network none mysolutionname:somerandomidentifier
The container will automatically process all PDFs in
/app/inputand generate corresponding.jsonfiles in/app/output.
The system outputs JSON files with the following structure:
{
"title": "Understanding AI",
"outline": [
{ "level": "H1", "text": "Introduction", "page": 1 },
{ "level": "H2", "text": "What is AI?", "page": 2 },
{ "level": "H3", "text": "History of AI", "page": 3 }
]
}The title is automatically extracted from the largest heading among the first 4 headings in close proximity on the first page.