pdflisted
Install: claude install-skill Wide-Moat/open-computer-use
# PDF Processing Guide
## Overview
This guide covers essential PDF processing operations using Python libraries and command-line tools. For advanced features, JavaScript libraries, and detailed examples, see REFERENCE.md. If you need to fill out a PDF form, read FORMS.md and follow its instructions.
## Quick Start
```python
from pypdf import PdfReader, PdfWriter
# Read a PDF
reader = PdfReader("document.pdf")
print(f"Pages: {len(reader.pages)}")
# Extract text
text = ""
for page in reader.pages:
text += page.extract_text()
```
### CRITICAL: Large PDF Safeguards
Before processing any PDF, check its size and page count:
```python
import os
from pypdf import PdfReader
file_path = "document.pdf"
size_mb = os.path.getsize(file_path) / (1024 * 1024)
reader = PdfReader(file_path)
page_count = len(reader.pages)
print(f"Size: {size_mb:.1f} MB, Pages: {page_count}")
```
**Rules for large PDFs (>20 pages or >5MB):**
- NEVER extract text from ALL pages at once into a single string
- Extract only the pages you need: `reader.pages[0:5]`
- Process page by page, don't accumulate all text in memory
**WARNING — this overflows context on large PDFs:**
```python
# BAD:
text = ""
for page in reader.pages:
text += page.extract_text()
print(text) # Dumps EVERYTHING
```
**CORRECT:**
```python
for i in range(min(5, page_count)):
text = reader.pages[i].extract_text()
# Process this page immediately
```
## Python Libraries
### pypdf - Basic Operations
#### Merge PDFs
``