This document outlines the methodologies tested for parsing PDFs in Python, focusing on the optimal combination of Docling (for text/table extraction) and PyMuPDF (for images). Alternative methods (PyPDF, PDFPlumber, Camelot) were prototyped and archived under /prototyping.
| Library | Text Extraction | Image Extraction | Table Extraction | Speed | Complexity |
|---|---|---|---|---|---|
| PyPDF | Good (text-based) | Basic (no OCR) | Poor | Fast | Low |
| PyMuPDF | Good (text-based) | Excellent | Poor | Fast | Moderate |
| PDFPlumber | Good (text-based) | Good (no OCR) | Moderate | Moderate | High |
| Camelot | None | None | Good (But doesn't detect semi-lattice tables) | Slow | High |
| Docling | Excellent | Poor | Excellent (Detects all kinds of tables accurately) | Moderate | Moderate |
- Docling: Best for text (preserves structure) and AI-based table extraction but lacks in image extraction qualities.
- PyMuPDF: Superior for image extraction and fast text extraction.
- Camelot: Specialized for tables but requires Ghostscript on the OS level and Java.
- Combination: Docling + PyMuPDF covers text, tables, and images efficiently.
- Text & Tables:
- Docling extracts text and tables into structured Markdown/CSV.
- Uses AI models for complex layouts but may miss nested tables.
- Images:
- PyMuPDF extracts embedded images with metadata (resolution, format).
- Saves images as
PNG/JPEGwith page-wise naming.
- Accuracy: Docling preserves formatting; PyMuPDF handles high-res images.
- Speed: Parallel processing possible for large PDFs.
- Integration: Seamless S3 integration for cloud storage.
- Docling: Limited to text-based PDFs (no OCR for scanned files).
- PyMuPDF: No native table extraction.
For Unix/macOS
python -m venv venv source venv/bin/activate
For Windows
python -m venv venv .\venv\Scripts\activate
pip install -r requirements.txt
Run this command and enter the credentials provided:
aws configure
You'll be prompted for:
AWS Access Key ID: [YOUR_ACCESS_KEY]
AWS Secret Access Key: [YOUR_SECRET_KEY]
Default region name: us-east-2
Default output format: [Press enter for None]
Bucket Structure:
neu-pdf-webpage-parser/
├── pdfs/
│ ├── raw/ # Raw PDFs
│ ├── python-parser/ # Processed outputs
│ ├── extracted-text/ # Markdown files
│ ├── extracted-images/ # Images (PNG/JPEG)
│ ├── extracted-tables/ # CSV files
python python_pdf_extraction.py
deactivate # Exit the virtual environment
This setup ensures isolation of dependencies and reproducibility across environments. The virtual environment (venv/) and temporary files (temp_processing/) are excluded from Git via .gitignore.
- OCR Integration: Add Tesseract for scanned PDFs.
- Error Handling: Retry mechanisms for S3 uploads.
- Scalability: Batch processing for multiple PDFs.
The Docling + PyMuPDF combination balances accuracy, speed, and ease of integration with cloud workflows. Archived prototypes (PyPDF, PDFPlumber, Camelot) are available in /prototyping for reference.