Skip to main content

No project description provided

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.1.tar.gz (557.3 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.1-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pdftokenizer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 006fdcf6b7ef9b85f63a05a6b52d872cfd38a8a06e9e9944f26dc17680ea3663
MD5 3a0cacb1443ae11f5a09a52768f5d800
BLAKE2b-256 c934b339997cd8bba09417300a57c1319b9eb16bf3ef40ebcb9780d0e0bfbc0f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pdftokenizer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d3779360fc1a0fb9dd6092d83bdf5444acfd7982f025c2e829ec11f20926f60f
MD5 1a234a2eea5b15a792ac8c1e62b7e9b2
BLAKE2b-256 206b24e9d5bd912bc94c17f4eae46a312585aeadf7c17b8fd60004ba4ef6d11c

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