A Python package for processing PDFs with header and footer detection
Project description
PDF Section Parser
A Python package for automatically detecting and extracting headers, body text, and footers from PDF documents. The package supports multiple languages and provides both visual boundary detection and structured text extraction.
Features
- 📄 Automatic detection of headers, footers, and body sections in PDF documents
- 🌍 Multi-language support
- 🎯 Precise boundary detection for consistent text extraction
- 📊 JSON output with structured content
- 👁️ Visual PDF output showing detected boundaries
- 📁 Process single files or entire directories
- ⚙️ Flexible configuration options
Installation
pip install pdf-section-parser
Quick Start
from pdf_section_parser import PDFSectionParser, ParserConfig
# Use default settings (generate both PDF and JSON)
parser = PDFSectionParser()
parser.parse("path/to/document.pdf")
# Custom configuration
config = ParserConfig(
generate_boundaries_pdf=True,
generate_json=True,
output_dir="custom/output/dir"
)
parser = PDFSectionParser(config)
parser.parse("path/to/pdf/directory")
Command Line Usage
# Process a single file with default settings
pdf-section-parser single-file.pdf
# Process a directory of PDFs
pdf-section-parser path/to/pdf/directory
# Customize processing options
pdf-section-parser --no-boundaries-pdf path/to/document.pdf
# Get help
pdf-section-parser --help
Configuration Options
| Parameter | Default | Description |
|---|---|---|
generate_boundaries_pdf |
True | Generate PDF with visual boundary markers |
generate_json |
True | Generate JSON output with structured content |
output_dir |
None | Custom output directory (default: same as input) |
Output Format
JSON Output
{
"pdf_with_lines": "document_final_boundaries.pdf",
"pages": [
{
"number": 1,
"header": "Header text...",
"body": "Main content...",
"footer": "Footer text..."
}
]
}
Visual PDF Output
The package generates a PDF file with colored lines showing detected boundaries:
- 🔵 Blue lines: Header boundaries
- 🟢 Green lines: Bottom footer boundaries
- 🔴 Red lines: Right footer boundaries
Requirements
- Python 3.8 or higher
- PyMuPDF (1.24.0 or higher)
- PyMuPDF4LLM (0.0.17 or higher)
- tqdm
Examples
Process Single File
from pdf_section_parser import PDFSectionParser
parser = PDFSectionParser()
parser.parse("document.pdf")
Process Directory
parser = PDFSectionParser()
parser.parse("path/to/pdf/directory")
Custom Configuration
from pdf_section_parser import PDFSectionParser, ParserConfig
config = ParserConfig(
generate_boundaries_pdf=False, # Skip boundary PDF generation
generate_json=True, # Generate JSON output
output_dir="output" # Custom output directory
)
parser = PDFSectionParser(config)
parser.parse("document.pdf")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the GNU Affero General Public License v3 (AGPL-3.0).
This program incorporates work covered by the following copyright and permission notices:
PyMuPDF (https://github.com/pymupdf/PyMuPDF) Copyright (c) 2016-2024 Artifex Software, Inc. Licensed under GNU Affero General Public License version 3
Contact
Tamara Orlich - [tamara.orlich@borah.agency]
Project Link: [https://github.com/BorahLabs/spanish_pdf_parser]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spanish_pdf_parser-0.1.0.tar.gz.
File metadata
- Download URL: spanish_pdf_parser-0.1.0.tar.gz
- Upload date:
- Size: 52.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ec9386ea60df718e1be0c8042f7aa8fda06a8194611b9d5e0ef59a6ab89c9b1
|
|
| MD5 |
33cd278d8bb96a8ce0545dc16231986b
|
|
| BLAKE2b-256 |
c1c1755c1982430ac812120b4cf02db0cd9f7e00945a6e7a8f109f1bed2c1533
|
File details
Details for the file spanish_pdf_parser-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spanish_pdf_parser-0.1.0-py3-none-any.whl
- Upload date:
- Size: 40.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acc0fede98d14e6b45dba8ce1a08d9d310c8b3b0612356675f485a248dfc4537
|
|
| MD5 |
9fa2f9ab3d4a92e7ee104d0e1b730bf3
|
|
| BLAKE2b-256 |
9631d48410b5d0d183ba1b9e4685920963d220ba79df2a2da6132e96638d953a
|