Extract and process text from images and PDFs
Project description
Text Extraction
A Python package for extracting text from various document formats, including PDFs, images, and scanned documents. The package supports table detection, OCR, and password-protected PDF handling.
Features
- Extract text from regular PDFs
- Process scanned PDFs using OCR
- Extract text from images
- Detect and extract tables from PDFs
- Remove password protection from PDFs
- Generate markdown output with proper formatting
- Support for multiple OCR engines (Tesseract, EasyOCR)
- Dictionary-based text correction
Installation
# Clone the repository
git clone https://github.com/yourusername/textextraction.git
cd textextraction
# Install dependencies
pip install -r requirements.txt
# Install the package
pip install -e .
Usage
Basic PDF Text Extraction
from textextraction import PdfText
# Initialize the PDF processor
pdf_processor = PdfText(add_page_number=True)
# Extract text from a PDF
pdf_processor.process("input.pdf", "output.md")
Scanned PDF Processing
from textextraction import ScannedPdfText
# Initialize the scanned PDF processor
scanned_processor = ScannedPdfText(
add_page_number=True,
dictionary=True, # Enable dictionary-based correction
add_metadata=True
)
# Process a scanned PDF
scanned_processor.process("scanned.pdf", "output.md")
Image Text Extraction
from textextraction import ImageText
# Initialize the image processor
image_processor = ImageText(dictionary=True)
# Extract text from an image
image_processor.process("image.jpg", "output.md")
Table Extraction
from textextraction import PdfText
# Initialize with table detection enabled
pdf_processor = PdfText(table_detection=True)
# Extract text and tables from a PDF
pdf_processor.process("input.pdf", "output.md")
PDF Unlocking
from textextraction import PdfUnlocker
# Initialize the PDF unlocker
unlocker = PdfUnlocker()
# Remove password protection
unlocker.unlock("protected.pdf", "password", "unlocked.pdf")
Command Line Interface
The package also provides a command-line interface:
# Unlock a password-protected PDF
python -m textextraction unlock input.pdf password -o output.pdf
# Process a PDF with table detection
python -m textextraction process input.pdf --table-detection -o output.md
# Process a scanned PDF with OCR
python -m textextraction process scanned.pdf --scanned --ocr -o output.md
Advanced Options
PDF Processing
from textextraction import PdfText
# Initialize with custom options
pdf_processor = PdfText(
add_page_number=True, # Add page numbers to output
dictionary=True, # Enable dictionary-based correction
add_metadata=True, # Include PDF metadata
table_detection=True # Enable table detection
)
# Process specific page range
pdf_processor.process(
"input.pdf",
"output.md",
start_page=1, # Start from page 1
end_page=5 # End at page 5
)
Scanned PDF Processing
from textextraction import ScannedPdfText
# Initialize with OCR options
scanned_processor = ScannedPdfText(
add_page_number=True,
dictionary=True,
add_metadata=True,
table_detection=True,
ocr_engine="easyocr" # Choose between "tesseract" or "easyocr"
)
# Process with custom page range
scanned_processor.process(
"scanned.pdf",
"output.md",
start_page=1,
end_page=5
)
Output Format
The package generates markdown output with the following features:
- Page numbers (if enabled)
- Properly formatted tables
- Preserved document structure
- Metadata (if enabled)
- Clean text formatting
Example output:
# Document Title
## Page 1
This is the first page of the document.
| Column 1 | Column 2 |
|----------|----------|
| Data 1 | Data 2 |
| Data 3 | Data 4 |
## Page 2
This is the second page...
Dependencies
- PyPDF2/pypdfium2 - PDF processing
- Tesseract OCR - Text recognition
- EasyOCR - Alternative OCR engine
- Pillow - Image processing
- NumPy - Numerical operations
- OpenCV - Image processing
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file textextraction-0.1.4.tar.gz.
File metadata
- Download URL: textextraction-0.1.4.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe7988c6410a6138a929e0f5bad69a465f4b124851975b8343100df37ba040de
|
|
| MD5 |
e40205be4f9e948323da0d157960a518
|
|
| BLAKE2b-256 |
9fe728a6ba16780feda34b3953e28f311959a06f92b8864923e405eaf63befa2
|
File details
Details for the file textextraction-0.1.4-py3-none-any.whl.
File metadata
- Download URL: textextraction-0.1.4-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c240de6a4025c4ca64a5ce7f3b1cbce0d8994881f0720fe7e659a256e2ea56e7
|
|
| MD5 |
645288e8bd23dabea8df8a3769ba2255
|
|
| BLAKE2b-256 |
e4b8cba03798a14b86308cd1046887a54536c29262afa870f9b4409874adbbc1
|