ocr_pdf2txt
A comprehensive Python library for extracting text from PDF files using OCR with advanced features such as layout visualization, audio generation, table extraction, summarization, and translation.
Features
- Text Extraction: Extracts text from PDF files using Tesseract OCR.
- Layout Visualization: Generates HTML files with OCR overlays to visualize recognized text regions.
- Audio Output: Converts extracted text into audio files using gTTS.
- Semantic Topic Detection: Identifies high-level semantic topics from the extracted text using spaCy.
- Advanced Summarization: Summarizes the extracted text using Hugging Face transformers.
- Translation: Translates extracted text into specified languages using googletrans.
- Table Extraction: Extracts tables from PDFs into CSV files using tabula-py.
- Batch Processing: Processes multiple PDFs concurrently for efficient workflows.
Installation
Prerequisites
- Python 3.7+
- Tesseract OCR:
- macOS:
brew install tesseract - Windows: Download from Tesseract at UB Mannheim
- Linux: Install via package manager, e.g.,
sudo apt-get install tesseract-ocr
- macOS:
- Poppler: Required by
pdf2image- macOS:
brew install poppler - Windows: Download from Poppler for Windows
- Linux: Install via package manager, e.g.,
sudo apt-get install poppler-utils
- macOS:
- Java: Required by
tabula-py- All OS: Download and install from Java Downloads
Install the Library
pip install ocr_pdf2txt
Usage
Single PDF Processing
from ocr_pdf2txt import ocr_pdf_to_text
pdf_path = "path/to/your/input.pdf"
output_folder = "path/to/output_folder"
ocr_pdf_to_text(
pdf_path=pdf_path,
output_folder=output_folder
)
Batch PDF Processing
from ocr_pdf2txt import ocr_batch_pdfs_to_text
pdf_list = [
"path/to/your/first.pdf",
"path/to/your/second.pdf",
# Add more PDF paths
]
output_folder = "path/to/output_directory"
ocr_batch_pdfs_to_text(
pdf_paths=pdf_list,
output_folder=output_folder,
max_workers=4
)
Extract Text Only
from ocr_pdf2txt import pdf_to_text_only
pdf_path = "path/to/your/input.pdf"
text = pdf_to_text_only(pdf_path)
print(text)
Extract Tables
from ocr_pdf2txt import extract_tables_from_pdf
pdf_path = "path/to/your/input.pdf"
output_csv = "path/to/output.csv"
extract_tables_from_pdf(pdf_path, output_csv, pages="all")
API
ocr_pdf_to_text
Extracts text from a PDF file using OCR and saves the output to a text file.
def ocr_pdf_to_text(
pdf_path: str,
output_folder: str
):
Extracts text from a single PDF file and performs the following:
- Layout Visualization: Creates HTML overlays of OCR results
- Audio Output: Generates an MP3 file of the extracted text
- Semantic Topic Detection: Prints detected named entity labels
- Advanced Summarization: Summarizes the extracted text
- Translation: Translates the extracted text into Spanish
pdf_to_text_only
def pdf_to_text_only(pdf_path: str) -> str:
Extracts text from a single PDF and returns it as a string.
extract_tables_from_pdf
def extract_tables_from_pdf(pdf_path: str, output_csv_path: str, pages: str = "all"):
Extracts tables from a PDF and saves them as a CSV file.
ocr_batch_pdfs_to_text
def ocr_batch_pdfs_to_text(
pdf_paths: List[str],
output_folder: str,
max_workers: int = 4
):
Processes multiple PDFs concurrently, performing all OCR operations on each.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for ocr-pdf2txt 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ocr_pdf2txt-0.1.2.tar.gz | 4.5 kB | Without provenance | Details for ocr_pdf2txt-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ocr_pdf2txt-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for ocr_pdf2txt-0.1.2-py3-none-any.whl |
Total release size: 9.2 kB
Release files / ocr_pdf2txt-0.1.2.tar.gz
| Download URL | ocr_pdf2txt-0.1.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5c938add3686d434235fd798ded48c6a1c9e6c0fd37495baeb86100472c60bc
|
|
BLAKE2b-256 checksum How to use checksums |
f774079d01142b4a35f26ec18bb37760c3765ca4662d6d7f7e9d16ae92bd8d69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Release files / ocr_pdf2txt-0.1.2-py3-none-any.whl
| Download URL | ocr_pdf2txt-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
488e8f78df5eee696a75eaeba3e3c9e7742556d32a92f694ce455e7c9571ad8d
|
|
BLAKE2b-256 checksum How to use checksums |
2a65463d4c651ed960c22d44f7fdba050b1ea02c334c74624cdf52bef8325012
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Security for ocr-pdf2txt 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.