Skip to main content

Tool to extract PAWLs tokens from PDFs

Project description

PdfTokenizer

PyPI - Version PyPI - Python Version

A Python library for extracting text from PDFs with automatic OCR detection.

Features

  • 🔍 Smart OCR Detection: Automatically determines if OCR is needed by analyzing text extractability
  • 🔄 Dual Extraction Methods: Uses PdfPlumber for native PDFs and Tesseract for scanned documents
  • 🪟 Windows Support: Automatic Poppler download and setup for Windows users

Installation

pip install pdftokenizer

Quick Start

from pdftokenizer import extract_tokens_from_pdf

# Read your PDF file
with open("document.pdf", "rb") as f:
    pdf_bytes = f.read()

# Extract tokens - OCR will be used automatically if needed
pages = extract_tokens_from_pdf(pdf_bytes)

# Force OCR if desired
pages_ocr = extract_tokens_from_pdf(pdf_bytes, force_ocr=True)

How It Works

The library automatically determines whether to use OCR based on text extractability:

  1. Attempts to extract text from the PDF using PyPDF
  2. If the extracted text contains fewer than 10 characters (configurable threshold), the PDF is considered to need OCR
  3. Based on this detection:
    • Text-based PDFs: Processed using PdfPlumber for efficient extraction
    • Scanned/Image PDFs: Processed using Tesseract OCR

Requirements

Poppler

PDF processing backend:

  • Windows: Automatically downloaded and configured
  • Linux: apt-get install poppler-utils
  • macOS: brew install poppler

Tesseract

Required for OCR functionality:

  • Windows: Download from UB Mannheim
  • Linux: apt-get install tesseract-ocr
  • macOS: brew install tesseract

License

pdftokenizer is distributed under the terms of the MIT license.

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

pdftokenizer-0.0.4.tar.gz (562.0 kB view details)

Uploaded Source

Built Distribution

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

pdftokenizer-0.0.4-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file pdftokenizer-0.0.4.tar.gz.

File metadata

  • Download URL: pdftokenizer-0.0.4.tar.gz
  • Upload date:
  • Size: 562.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for pdftokenizer-0.0.4.tar.gz
Algorithm Hash digest
SHA256 3a96765251c72db93785d2b944db4aed8dfc6de158432c876f2646fccfad322b
MD5 5d2c8c26f50f9eba0f92f2902729eba2
BLAKE2b-256 1e241f21bae8c1e275ed979c6c0767ca9db35c5b1636d4ca708a7a39fd1ff267

See more details on using hashes here.

File details

Details for the file pdftokenizer-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pdftokenizer-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for pdftokenizer-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 22dae8bde95c1d5d44d3b5193abb1e4b344496b18edc500362eb8a71f082e4a5
MD5 4b23ccd08fd6d9a8c4897afe15264a49
BLAKE2b-256 6884c6af22d290ff10e03a9dfdb399d75fd5f5659e4f1a8017388e08923ca51f

See more details on using hashes here.

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