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
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()
Library & Tool Recipes
All Python library examples (pypdf, pdfplumber, reportlab), CLI tools (pdftotext, qpdf, pdftk), and common tasks (OCR, watermarks, image extraction, encryption):
references/pdf-recipes.md
Quick Reference
| Task |
Best Tool |
Command/Code |
| Merge PDFs |
pypdf |
writer.add_page(page) |
| Split PDFs |
pypdf |
One page per file |
| Extract text |
pdfplumber |
page.extract_text() |
| Extract tables |
pdfplumber |
page.extract_tables() |
| Create PDFs |
reportlab |
Canvas or Platypus |
| Command line merge |
qpdf |
qpdf --empty --pages ... |
| OCR scanned PDFs |
pytesseract |
Convert to image first |
| Fill PDF forms |
pdf-lib or pypdf (see FORMS.md) |
See FORMS.md |
Next Steps
- For advanced pypdfium2 usage, see REFERENCE.md
- For JavaScript libraries (pdf-lib), see REFERENCE.md
- If you need to fill out a PDF form, follow the instructions in FORMS.md
- For troubleshooting guides, see REFERENCE.md
1---2name: pdf3description: "Read, create, combine, split, rotate, OCR, watermark, secure, or extract content from PDF files. Use when a PDF is a primary input or requested output. Not for LaTeX source editing or Word and spreadsheet deliverables."4license: Proprietary. LICENSE.txt has complete terms5allowed-tools: Bash(uv*, pdftotext*, qpdf*, pdftk*, mkdir*, ls*), Read, Write6---78# PDF Processing Guide910## Overview1112This 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.1314## Quick Start1516```python17from pypdf import PdfReader, PdfWriter1819# Read a PDF20reader = PdfReader("document.pdf")21print(f"Pages: {len(reader.pages)}")2223# Extract text24text = ""25for page in reader.pages:26 text += page.extract_text()27```2829## Library & Tool Recipes3031All Python library examples (pypdf, pdfplumber, reportlab), CLI tools (pdftotext, qpdf, pdftk), and common tasks (OCR, watermarks, image extraction, encryption):3233**[references/pdf-recipes.md](references/pdf-recipes.md)**3435## Quick Reference3637| Task | Best Tool | Command/Code |38|------|-----------|--------------|39| Merge PDFs | pypdf | `writer.add_page(page)` |40| Split PDFs | pypdf | One page per file |41| Extract text | pdfplumber | `page.extract_text()` |42| Extract tables | pdfplumber | `page.extract_tables()` |43| Create PDFs | reportlab | Canvas or Platypus |44| Command line merge | qpdf | `qpdf --empty --pages ...` |45| OCR scanned PDFs | pytesseract | Convert to image first |46| Fill PDF forms | pdf-lib or pypdf (see FORMS.md) | See FORMS.md |4748## Next Steps4950- For advanced pypdfium2 usage, see REFERENCE.md51- For JavaScript libraries (pdf-lib), see REFERENCE.md52- If you need to fill out a PDF form, follow the instructions in FORMS.md53- For troubleshooting guides, see REFERENCE.md