Skip to main content

Docling wrapper for PDF parsing

Project description

PdfPlucker

PyPI version Python 3.12+ License: MIT

PdfPlucker is a powerful wrapper for the Docling library, specifically designed for batch processing PDF files. It provides users with fine-grained control over processing parameters and output configuration through a simple command-line interface.

Features

  • Comprehensive Extraction: Extract text, tables, and images from PDF files with high fidelity
  • Structured Outputs: Get results in well-organized JSON and Markdown formats
  • High Performance: Process multiple documents simultaneously with parallel processing
  • Hardware Acceleration: Support for both CPU and CUDA for faster processing
  • Simple Interface: Intuitive CLI commands for easy parameter control
  • Batch Processing: Handle directories of PDFs effortlessly

Installation

PdfPlucker requires Python 3.12 or higher. To install, simply run the following command:

pip install pdfplucker

if you want GPU support, run:

pip install pdfplucker[gpu]

Note: For GPU support, you may need to install the PyTorch version that matches your CUDA version. Check your CUDA version with nvidia-smi and visit https://pytorch.org/get-started/locally/ for instructions

Or install from source:

git clone https://github.com/rafaelghiorzi/pdfplucker.git
cd pdfplucker
pip install -r requirements.txt

Requirements

  • Python 3.12+
  • For CUDA support: An NVIDIA GPU with drivers up to date
  • Additional dependencies are automatically installed with the package

Basic Usage

PdfPlucker has a built-in CLI to run the processor. The basic command structure is:

pdfplucker --source /path/to/pdf

This will process the PDF file and save the results to ./results by default.

Command-line Options

Option Description
-s, --source Path to PDF files (directory or single file)
-o, --output Path to save processed information (default: ./results)
-f, --folder-separation Create separate folders for each PDF
-i, --images Path to save extracted images (ignored if --folder-separation is active)
-t, --timeout Time limit in seconds for processing each PDF (default: 600)
-w, --workers Number of parallel processes (default: 4)
-d, --device Processing device: CPU, CUDA, or AUTO (default: AUTO)
-m, --markdown Export the document in an additional markdown file
-ocr, --force-ocr Force text recognition using ocr even with digital documents

Markdown Output

When enabled with the --markdown flag, PdfPlucker will generate a readable Markdown file that includes:

  • Formatted document text
  • Tables rendered in Markdown syntax
  • Embedded images with base64 encoding

Force OCR option

Docling will extract text from natively digital PDFs. If you wish to force the use of OCR tools to scan the file text, run the command with the --force-ocr flag.

Amount of workers

When processing large amounts of files, note that many workers might lead to RAM shortage and memory leaks, mainly when paired with forced ocr. Try balancing the amount of workers with the amount of available memory and power of your computer.

Examples

Process a single PDF file:

pdfplucker --source document.pdf

Process all PDFs in a directory:

pdfplucker --source ./documents/ --output ./extracted_data

Create separate folders for each PDF and include markdown output:

pdfplucker --source ./documents/ --folder-separation --markdown

Specify output location for extracted images:

pdfplucker --source document.pdf --images ./images

Use CUDA for processing with 8 workers:

pdfplucker --source ./documents/ --device CUDA --workers 8

Advanced Usage

For processing large batches of PDFs, you can use the folder separation option combined with multiple workers:

pdfplucker --source ./pdf_collection/ --folder-separation --workers 8 --timeout 300 --force-ocr

This will create a separate folder for each PDF, use 8 parallel processes, set a timeout of 5 minutes per PDF and force ocr usage for text recognition.

Output Structure

PdfPlucker generates structured outputs in the following formats:

JSON Output

The JSON output contains:

  • Document metadata (title, author, date, etc.)
  • Extracted text divided into sections (title, text)
  • Table data with structure preserved and subtitles, if they exist
  • References to extracted images, with subtitles, if they exist

Example structure:

{
    "metadata": {
        "format": "PDF 1.7",
        "title": "Microsoft Word - Sample Title",
        "..."
        "producer": "Microsoft: Print To PDF",
        "creationDate": "D:20250401144737-03'00'",
        "filename": "file.pdf"
    },
    "sections": [
        {
            "title": "Big Title!",
            "text": "Following text after title"
        },
    ],
    "images": [
      {
        "self_ref" : "#picture/1",
        "ref" : "path/to/image.png",
        "subtitle" : "possible subtitle"
      }
    ],
    "tables": [
      {
        "self_ref" : "#table/1",
        "subtitle" : "possible subtitle",
        "table" : {"table in dict format"}
      }
    ]
}

Troubleshooting

Common Issues

  • MemoryError: Try reducing the number of workers or processing larger PDFs individually
  • CUDA not detected: Ensure you have compatible NVIDIA drivers installed and visible to Python
  • Timeout errors: Increase the timeout value for complex or large documents
  • Missing images: Check file permissions in the output directory

Getting Help

If you encounter issues not covered here, please open an issue on GitHub with:

  • The command you ran
  • The error message
  • Your system specifications (OS, Python version, etc.)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! If you have suggestions for improvements or new features, please:

  1. Check existing issues and pull requests
  2. Fork the repository
  3. Create a new branch for your feature
  4. Add your changes
  5. Submit a pull request

Acknowledgments

  • Docling for the core PDF processing capabilities
  • All contributors and users of PdfPlucker

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdfplucker-0.3.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdfplucker-0.3.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file pdfplucker-0.3.0.tar.gz.

File metadata

  • Download URL: pdfplucker-0.3.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pdfplucker-0.3.0.tar.gz
Algorithm Hash digest
SHA256 63e8445475a3a152148346cf8b78af664f79d6d8486fed964ca7fa576714b51c
MD5 0cab48b851aaf4757caa4bfbab179e82
BLAKE2b-256 51d8af0add69921748a6892e6ec0e72e08dc2b47a6816a03629afce76d129abd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfplucker-0.3.0.tar.gz:

Publisher: release.yaml on rafaelghiorzi/pdfplucker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pdfplucker-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pdfplucker-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pdfplucker-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff53c70e51db8c0a160b1d0468c07a1db3940262fa6e8eece1b9bbff0b57a525
MD5 d3aa32b1486fb58a1b9ccd779569b475
BLAKE2b-256 c1f706766dad9bb78d25f7ebfebe168f154045a5e36d1c435b433a3b6377509e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfplucker-0.3.0-py3-none-any.whl:

Publisher: release.yaml on rafaelghiorzi/pdfplucker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page