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.3.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.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdftokenizer-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 614f734493551b178d5d1f390cce3d275685efc32b0e18c7a14950b2bd10000b
MD5 83152d2c03156feac9f5e8c772d6cb34
BLAKE2b-256 4face8ac300fece86d63be2f21e06caff718872953d772010d14bfc146d08860

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdftokenizer-0.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 598387a30f2bea206f4ba2553ea183d1a93b33c5d4f812f7af2041cb57e25e31
MD5 351e21d735825d28e443dfe735077fa7
BLAKE2b-256 25491787bd96876111b71d60cf8c1f52bfbe2a355e943df11005ed50113678b6

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