Skip to main content

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]

Release files for spanish-pdf-parser 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spanish-pdf-parser 0.1.0
File Size Uploaded
spanish_pdf_parser-0.1.0.tar.gz 52.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spanish-pdf-parser 0.1.0
File Interpreter ABI Platform
spanish_pdf_parser-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 92.4 kB

Release files / spanish_pdf_parser-0.1.0.tar.gz

Download URL spanish_pdf_parser-0.1.0.tar.gz
Size 52.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4ec9386ea60df718e1be0c8042f7aa8fda06a8194611b9d5e0ef59a6ab89c9b1
BLAKE2b-256 checksum
How to use checksums
c1c1755c1982430ac812120b4cf02db0cd9f7e00945a6e7a8f109f1bed2c1533
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release files / spanish_pdf_parser-0.1.0-py3-none-any.whl

Download URL spanish_pdf_parser-0.1.0-py3-none-any.whl
Size 40.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
acc0fede98d14e6b45dba8ce1a08d9d310c8b3b0612356675f485a248dfc4537
BLAKE2b-256 checksum
How to use checksums
9631d48410b5d0d183ba1b9e4685920963d220ba79df2a2da6132e96638d953a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page