read-bin-docs
Straightforward text extraction from document files (text-based PDF only for now, no OCR or docx). Use when you just need to read/extract text from binary documents.
When & Why to Use This Skill
This Claude skill provides a streamlined solution for extracting text from text-based PDF documents. By leveraging the pypdf library, it enables users to programmatically or via command line retrieve content from binary files, facilitating seamless data integration and document analysis without the need for manual copy-pasting. It is ideal for developers and researchers who need to convert static PDF content into searchable, processable text formats.
Use Cases
- Automated Report Analysis: Quickly extract text from high-volume financial or research reports to generate summaries or identify key insights.
- Data Pipeline Integration: Use the provided Python snippets to programmatically feed document content into databases or AI-driven workflows.
- Selective Content Extraction: Isolate and extract specific page ranges from lengthy PDF documents to focus on relevant sections like legal clauses or executive summaries.
- Bulk Document Processing: Utilize the command-line interface to automate text extraction across multiple files for archival, indexing, or search optimization purposes.
| name | read-bin-docs |
|---|---|
| description | Straightforward text extraction from document files (text-based PDF only for now, no OCR or docx). Use when you just need to read/extract text from binary documents. |
Doc Formats
Quick Start: Extract Text from PDF
Need to extract text from a PDF? Use this Python snippet:
from pypdf import PdfReader
reader = PdfReader("document.pdf")
text = "".join(page.extract_text() for page in reader.pages)
print(text)
Or from the command line:
uvx --with pypdf python /path/to/extract_pdf_text.py document.pdf
PDF Text Extraction
Basic Usage
from pypdf import PdfReader
# Read all pages
reader = PdfReader("file.pdf")
for page in reader.pages:
text = page.extract_text()
print(text)
Extract Specific Pages
from pypdf import PdfReader
reader = PdfReader("file.pdf")
# Get pages 1-5 (0-indexed)
for page in reader.pages[0:5]:
print(page.extract_text())
Using the Script
This skill includes scripts/extract_pdf_text.py for command-line extraction:
# Extract all pages to stdout
python extract_pdf_text.py document.pdf
# Extract to file
python extract_pdf_text.py document.pdf --output text.txt
# Extract specific pages
python extract_pdf_text.py document.pdf --pages 1-5
python extract_pdf_text.py document.pdf --pages 1,3,5
Requirements
- pypdf:
uvx --with pypdf python <script> - Works with most text-based PDFs
- Scanned PDFs without OCR won't extract text
Common Issues
"No text extracted": The PDF may be scanned (image-based) without OCR. OCR support requires additional tools.
"Encoding errors": pypdf handles most encodings, but some PDFs may have encoding issues. Use page.extract_text(layout=True) for layout-aware extraction if available.
Future: Support for DOCX, XLSX, and other formats coming soon.