Document PDF Skill — Quick Reference
This skill enables PDF creation, extraction, manipulation, and analysis. Apply these patterns when users need to generate invoices, reports, extract data from PDFs, merge documents, or work with PDF forms.
Modern Best Practices (Jul 2026):
- PDF is a release artifact, not the editable source of truth.
- Validate export fidelity (fonts, images, links) and accessibility where required.
- Accessibility: if compliance matters, target a tagged/structured PDF workflow (often PDF/UA-aligned) and validate with tooling.
- EU distribution: EAA (June 2025) typically implies EN 301 549 expectations for customer-facing PDFs.
- Treat PDFs as sensitive: scrub metadata at all layers (PDF-internal, filesystem, OS xattrs), ensure real redaction, and control distribution.
- Metadata exists in multiple layers: PDF Info/XMP (internal), filesystem dates (OS), and extended attributes (macOS quarantine, provenance). Scrubbing one layer while ignoring others leaves traces.
Core Decision Rules (2026)
- First decide: born-digital PDF (selectable text) vs scanned PDF (images). Scanned PDFs usually require OCR; see
references/pdf-extraction-patterns.md.
- If the user needs accessibility/compliance, prefer generating from a source format that supports structure (DOCX/HTML + proper export) rather than “post-fixing” an untagged PDF.
- For deterministic ops (merge/split/rotate/scrub), prefer
scripts/ helpers over re-implementing ad hoc.
- Never treat black rectangles or overlays as redaction; use real redaction and verify by copy/paste + search.
- Table extraction is probabilistic, not deterministic: run
pdfplumber first and spot-check output against the source page; escalate to Camelot only when columns/rows are visibly wrong, and always inspect Camelot's per-table accuracy score rather than trusting output blindly.
PyMuPDF/fitz (used by scrub_metadata.py and most redaction/OCR-prep code below) is dual-licensed AGPL-3.0 / commercial. Flag this before shipping it inside a closed-source product or SaaS backend — AGPL's network-use clause can trigger a source-disclosure obligation; get a commercial license from Artifex or substitute pypdf/pdfplumber where the required functionality overlaps.
pdf-lib (Node) has had no active upstream releases for an extended period as of mid-2026; for new Node projects needing ongoing fixes, evaluate a maintained fork (e.g. @cantoo/pdf-lib) before committing, and pin the dependency either way.
Quick Reference
| Task |
Tool/Library |
Language |
When to Use |
| Create PDF |
pdfkit |
Node.js |
Reports, invoices, certificates |
| Create PDF |
ReportLab |
Python |
Complex layouts, tables |
| Create PDF |
FPDF2 |
Python |
Simple PDFs with Unicode support |
| Edit PDF |
pdf-lib |
Node.js |
Modify existing PDFs, add pages (upstream low-activity — consider a maintained fork) |
| Parse/merge/split/rotate |
pypdf |
Python |
Deterministic PDF manipulation |
| Extract text |
pdfplumber |
Python |
OCR-free text extraction |
| OCR scanned PDF |
OCRmyPDF |
Python/CLI |
Searchable text layer for scanned PDFs |
| Custom OCR pipeline |
PyMuPDF (fitz) + Tesseract |
Python |
Page-level OCR or image-heavy extraction — PyMuPDF is AGPL-3.0/commercial dual-licensed |
| Extract tables |
pdfplumber |
Python |
Default table extraction; verify visually before trusting |
| Extract hard tables |
Camelot (camelot-py) |
Python |
Lattice/stream edge cases; 2026 releases add an optional neural backend — check table.accuracy either way |
| Fill forms |
pdf-lib |
Node.js |
Form automation |
| Sign PDFs |
pyHanko |
Python/CLI |
Digital signatures and validation |
| HTML to PDF |
Playwright |
Node.js |
Browser-faithful web page rendering |
| HTML to tagged PDF |
WeasyPrint |
Python |
Semantic HTML, PDF/A or PDF/UA-oriented export |
| Validate PDF/A |
veraPDF |
CLI/GUI |
Archival conformance checks |
| Validate PDF accessibility |
PAC / Acrobat Checker |
GUI |
PDF/UA and accessibility checks |
| Inspect/edit file metadata |
exiftool |
CLI |
Audit or rewrite internal dates, XMP, EXIF, ICC across PDF/image files |
| Set filesystem dates |
touch / SetFile |
CLI (macOS) |
Correct creation/modification timestamps at OS level |
When to Use This Skill
Use this skill when a user requests:
- Generate PDFs from data (invoices, reports, certificates)
- Extract text or tables from existing PDFs
- Merge multiple PDFs into one document
- Split PDFs into separate files
- Fill PDF forms programmatically
- Add watermarks, headers, footers
- Convert HTML/web pages to PDF
Default Workflow
- Create: use
Playwright for browser-faithful HTML/CSS, WeasyPrint for semantic/tagged HTML exports, ReportLab for Python-heavy layouts, or pdfkit for Node-first custom layout.
- Extract: first classify the file as born-digital vs scanned; run
OCRmyPDF before downstream extraction on scanned PDFs, then use references/pdf-extraction-patterns.md.
- Ship: run
assets/pdf-release-checklist.md; add PAC / Acrobat checks for accessibility-sensitive PDFs and veraPDF when archival conformance matters.
ASCII Flow
PDF request
|
v
Classify task
|-- create new PDF
|-- extract text / tables / images
|-- modify existing PDF
|-- fill / sign forms
|-- merge / split / rotate / scrub
|
v
Classify source and risk
|-- born-digital ----> extract directly
|-- scanned ---------> OCR first
|-- sensitive -------> real redaction + metadata scrub
|-- compliance ------> tagged / structured source workflow
|
v
Select tool or script
|-- HTML/CSS --------> Playwright or WeasyPrint
|-- Python layout ---> ReportLab / FPDF2
|-- deterministic ---> scripts/ + pypdf
|-- extraction ------> pdfplumber / OCRmyPDF / Camelot
|
v
Verify fidelity, accessibility, metadata, and redaction
Scripts (Deterministic Operations)
Scripts are optional helpers; they assume Python 3 plus the listed dependencies in each file.
- Merge:
python3 scripts/merge_pdfs.py merged.pdf a.pdf b.pdf
- Split:
python3 scripts/split_pdf.py in.pdf out_dir --each-page
- Rotate:
python3 scripts/rotate_pdf.py in.pdf out.pdf --degrees 90
- Scrub metadata and active content:
python3 scripts/scrub_metadata.py in.pdf out.pdf
- Scrub with filesystem + xattr cleanup:
python3 scripts/scrub_metadata.py in.pdf out.pdf --filesystem-date 2025-09-20 --strip-xattrs
PDF Structure Patterns
Invoice Template
INVOICE STRUCTURE
├── Header (logo, company info, invoice #)
├── Bill To / Ship To blocks
├── Line items table
│ ├── Description | Qty | Unit Price | Total
│ └── Subtotal, Tax, Total
├── Payment terms
└── Footer (contact, thank you)
Report Template
REPORT PDF STRUCTURE
├── Cover page (title, author, date)
├── Table of contents
├── Body sections with page numbers
├── Charts/images with captions
├── Appendices
└── Running header/footer
Decision Tree
PDF Task: [What do you need?]
├─ Create new PDF?
│ ├─ Browser-faithful HTML/CSS → Playwright
│ ├─ Semantic HTML / tagged export → WeasyPrint
│ ├─ Node-first custom layout → pdfkit
│ └─ Python complex layout → ReportLab / FPDF2
│
├─ Extract from PDF?
│ ├─ Born-digital text → pdfplumber (Python)
│ ├─ Scanned pages → OCRmyPDF, then pdfplumber
│ ├─ Tables → pdfplumber first, Camelot for hard cases
│ └─ Images / raster work → PyMuPDF/fitz
│
├─ Modify existing PDF?
│ ├─ Add text/images → pdf-lib (Node)
│ ├─ Merge/split/rotate/scrub → pypdf + scripts
│ ├─ Fill forms → pdf-lib
│ └─ Sign → pyHanko
│
└─ Batch processing?
└─ OCRmyPDF / pypdf / pdfplumber pipeline
Do / Avoid (Jul 2026)
Do
- Keep a versioned source document (doc/slide/design file) alongside the PDF.
- Verify links and reading order for long documents.
- Use real redaction and test by copy/paste.
- Use
OCRmyPDF for scanned PDFs before text extraction.
- Scrub all metadata layers before distribution (PDF-internal, filesystem dates, macOS xattrs).
- Verify with
exiftool -all -G1 after scrubbing — check for tool fingerprints (XMP Toolkit) and residual dates.
- Confirm PyMuPDF's AGPL/commercial licensing fits the deployment before relying on it in closed-source or SaaS code paths.
Avoid
- Editing PDFs as the primary workflow when a source doc exists.
- Defaulting to
wkhtmltopdf in new 2026 workflows.
- Shipping PDFs with broken links or illegible charts.
- Including customer PII or secrets in PDFs without explicit approval.
- Scrubbing only PDF-internal metadata while ignoring filesystem dates and OS-level xattrs.
- Using exiftool to modify PDF XMP without overwriting its
XMP Toolkit fingerprint.
- Trusting
Camelot/pdfplumber table output on financial or legal documents without a visual spot-check or accuracy-score review — misaligned columns fail silently.
- Bundling PyMuPDF into a proprietary product without checking AGPL obligations or budgeting for a commercial license.
What Good Looks Like
- Fidelity: export is reproducible from a versioned source file (doc/slide/design) and looks identical across viewers.
- Accessibility: tags/reading order are correct; links work; scanned docs are OCRed when appropriate.
- Release hygiene: file naming includes version/date; metadata is clean; no “PDF as source of truth”.
- Security: redaction is verified (copy/paste test) and sensitive data is minimized.
- QA: release checklist completed using
assets/pdf-release-checklist.md.
Optional: AI / Automation
Use only when explicitly requested and policy-compliant.
- Generate a release checklist run; humans verify the final PDF manually.
Navigation
Resources
- references/pdf-generation-patterns.md — Complex layouts, multi-page docs
- references/pdf-extraction-patterns.md — Text, table, image extraction
- references/pdf-accessibility-compliance.md — Tagged PDFs, PDF/UA, EAA compliance
- references/pdf-forms-interactive.md — AcroForms, form filling, digital signatures
- references/pdf-security-redaction.md — Encryption, permissions, real redaction
- data/sources.json — Library documentation links
Scripts
scripts/merge_pdfs.py — Merge PDFs in order
scripts/split_pdf.py — Split one-per-page or by range
scripts/rotate_pdf.py — Rotate all pages by 90/180/270 degrees
scripts/scrub_metadata.py — Scrub Info/XMP metadata, attachments, JavaScript, and thumbnails
Templates
- assets/invoice-template.md — Invoice PDF generation
- assets/report-template.md — Multi-page report structure
- assets/pdf-release-checklist.md — Links, accessibility, export fidelity
Related Skills
Fact-Checking
- Use web search/web fetch to verify current external facts, versions, pricing, deadlines, regulations, or platform behavior before final answers.
- Prefer primary sources; report source links and dates for volatile information.
- If web access is unavailable, state the limitation and mark guidance as unverified.
Learnings Loop
Before applying this skill on a non-trivial task, read learnings.consolidated.md in this directory (and learnings.md if present).
After applying it, if you encountered a pattern worth remembering, a mistake worth preventing, or a domain fact that surprised you, append one dated bullet to learnings.md via agents-skills-feedback-loop/scripts/append_learning.py. Do not modify SKILL.md itself.
1---
2name: document-pdf
3description: Extracts, creates, and transforms PDF documents. Use when parsing text or tables, generating files, merging pages, or handling PDF forms.
4allowed-tools: Bash, Read, Write, Glob, Grep
5compatibility: Claude Code + Codex. Uses runtime-specific allowed-tools / argument-hint fields.
6version: "1.1"
7last_validated: 2026-07-11
8---
9
10# Document PDF Skill — Quick Reference
11
12This skill enables PDF creation, extraction, manipulation, and analysis. Apply these patterns when users need to generate invoices, reports, extract data from PDFs, merge documents, or work with PDF forms.
13
14**Modern Best Practices (Jul 2026)**:
15- PDF is a release artifact, not the editable source of truth.
16- Validate export fidelity (fonts, images, links) and accessibility where required.
17- Accessibility: if compliance matters, target a tagged/structured PDF workflow (often PDF/UA-aligned) and validate with tooling.
18- EU distribution: EAA (June 2025) typically implies EN 301 549 expectations for customer-facing PDFs.
19- Treat PDFs as sensitive: scrub metadata at all layers (PDF-internal, filesystem, OS xattrs), ensure real redaction, and control distribution.
20- Metadata exists in multiple layers: PDF Info/XMP (internal), filesystem dates (OS), and extended attributes (macOS quarantine, provenance). Scrubbing one layer while ignoring others leaves traces.
21
22## Core Decision Rules (2026)
23
24- First decide: born-digital PDF (selectable text) vs scanned PDF (images). Scanned PDFs usually require OCR; see `references/pdf-extraction-patterns.md`.
25- If the user needs accessibility/compliance, prefer generating from a source format that supports structure (DOCX/HTML + proper export) rather than “post-fixing” an untagged PDF.
26- For deterministic ops (merge/split/rotate/scrub), prefer `scripts/` helpers over re-implementing ad hoc.
27- Never treat black rectangles or overlays as redaction; use real redaction and verify by copy/paste + search.
28- Table extraction is probabilistic, not deterministic: run `pdfplumber` first and spot-check output against the source page; escalate to `Camelot` only when columns/rows are visibly wrong, and always inspect Camelot's per-table `accuracy` score rather than trusting output blindly.
29- `PyMuPDF`/`fitz` (used by `scrub_metadata.py` and most redaction/OCR-prep code below) is dual-licensed **AGPL-3.0 / commercial**. Flag this before shipping it inside a closed-source product or SaaS backend — AGPL's network-use clause can trigger a source-disclosure obligation; get a commercial license from Artifex or substitute `pypdf`/`pdfplumber` where the required functionality overlaps.
30- `pdf-lib` (Node) has had no active upstream releases for an extended period as of mid-2026; for new Node projects needing ongoing fixes, evaluate a maintained fork (e.g. `@cantoo/pdf-lib`) before committing, and pin the dependency either way.
31
32---
33
34## Quick Reference
35
36| Task | Tool/Library | Language | When to Use |
37|------|--------------|----------|-------------|
38| Create PDF | pdfkit | Node.js | Reports, invoices, certificates |
39| Create PDF | ReportLab | Python | Complex layouts, tables |
40| Create PDF | FPDF2 | Python | Simple PDFs with Unicode support |
41| Edit PDF | pdf-lib | Node.js | Modify existing PDFs, add pages (upstream low-activity — consider a maintained fork) |
42| Parse/merge/split/rotate | pypdf | Python | Deterministic PDF manipulation |
43| Extract text | pdfplumber | Python | OCR-free text extraction |
44| OCR scanned PDF | OCRmyPDF | Python/CLI | Searchable text layer for scanned PDFs |
45| Custom OCR pipeline | PyMuPDF (fitz) + Tesseract | Python | Page-level OCR or image-heavy extraction — **PyMuPDF is AGPL-3.0/commercial dual-licensed** |
46| Extract tables | pdfplumber | Python | Default table extraction; verify visually before trusting |
47| Extract hard tables | Camelot (camelot-py) | Python | Lattice/stream edge cases; 2026 releases add an optional neural backend — check `table.accuracy` either way |
48| Fill forms | pdf-lib | Node.js | Form automation |
49| Sign PDFs | pyHanko | Python/CLI | Digital signatures and validation |
50| HTML to PDF | Playwright | Node.js | Browser-faithful web page rendering |
51| HTML to tagged PDF | WeasyPrint | Python | Semantic HTML, PDF/A or PDF/UA-oriented export |
52| Validate PDF/A | veraPDF | CLI/GUI | Archival conformance checks |
53| Validate PDF accessibility | PAC / Acrobat Checker | GUI | PDF/UA and accessibility checks |
54| Inspect/edit file metadata | exiftool | CLI | Audit or rewrite internal dates, XMP, EXIF, ICC across PDF/image files |
55| Set filesystem dates | touch / SetFile | CLI (macOS) | Correct creation/modification timestamps at OS level |
56
57## When to Use This Skill
58
59Use this skill when a user requests:
60
61- Generate PDFs from data (invoices, reports, certificates)
62- Extract text or tables from existing PDFs
63- Merge multiple PDFs into one document
64- Split PDFs into separate files
65- Fill PDF forms programmatically
66- Add watermarks, headers, footers
67- Convert HTML/web pages to PDF
68
69---
70
71## Default Workflow
72
73- Create: use `Playwright` for browser-faithful HTML/CSS, `WeasyPrint` for semantic/tagged HTML exports, `ReportLab` for Python-heavy layouts, or `pdfkit` for Node-first custom layout.
74- Extract: first classify the file as born-digital vs scanned; run `OCRmyPDF` before downstream extraction on scanned PDFs, then use `references/pdf-extraction-patterns.md`.
75- Ship: run `assets/pdf-release-checklist.md`; add `PAC` / Acrobat checks for accessibility-sensitive PDFs and `veraPDF` when archival conformance matters.
76
77## ASCII Flow
78
79```text
80PDF request
81 |
82 v
83Classify task
84 |-- create new PDF
85 |-- extract text / tables / images
86 |-- modify existing PDF
87 |-- fill / sign forms
88 |-- merge / split / rotate / scrub
89 |
90 v
91Classify source and risk
92 |-- born-digital ----> extract directly
93 |-- scanned ---------> OCR first
94 |-- sensitive -------> real redaction + metadata scrub
95 |-- compliance ------> tagged / structured source workflow
96 |
97 v
98Select tool or script
99 |-- HTML/CSS --------> Playwright or WeasyPrint
100 |-- Python layout ---> ReportLab / FPDF2
101 |-- deterministic ---> scripts/ + pypdf
102 |-- extraction ------> pdfplumber / OCRmyPDF / Camelot
103 |
104 v
105Verify fidelity, accessibility, metadata, and redaction
106```
107
108## Scripts (Deterministic Operations)
109
110Scripts are optional helpers; they assume Python 3 plus the listed dependencies in each file.
111
112- Merge: `python3 scripts/merge_pdfs.py merged.pdf a.pdf b.pdf`
113- Split: `python3 scripts/split_pdf.py in.pdf out_dir --each-page`
114- Rotate: `python3 scripts/rotate_pdf.py in.pdf out.pdf --degrees 90`
115- Scrub metadata and active content: `python3 scripts/scrub_metadata.py in.pdf out.pdf`
116- Scrub with filesystem + xattr cleanup: `python3 scripts/scrub_metadata.py in.pdf out.pdf --filesystem-date 2025-09-20 --strip-xattrs`
117
118## PDF Structure Patterns
119
120### Invoice Template
121
122```text
123INVOICE STRUCTURE
124├── Header (logo, company info, invoice #)
125├── Bill To / Ship To blocks
126├── Line items table
127│ ├── Description | Qty | Unit Price | Total
128│ └── Subtotal, Tax, Total
129├── Payment terms
130└── Footer (contact, thank you)
131```
132
133### Report Template
134
135```text
136REPORT PDF STRUCTURE
137├── Cover page (title, author, date)
138├── Table of contents
139├── Body sections with page numbers
140├── Charts/images with captions
141├── Appendices
142└── Running header/footer
143```
144
145---
146
147## Decision Tree
148
149```text
150PDF Task: [What do you need?]
151 ├─ Create new PDF?
152 │ ├─ Browser-faithful HTML/CSS → Playwright
153 │ ├─ Semantic HTML / tagged export → WeasyPrint
154 │ ├─ Node-first custom layout → pdfkit
155 │ └─ Python complex layout → ReportLab / FPDF2
156 │
157 ├─ Extract from PDF?
158 │ ├─ Born-digital text → pdfplumber (Python)
159 │ ├─ Scanned pages → OCRmyPDF, then pdfplumber
160 │ ├─ Tables → pdfplumber first, Camelot for hard cases
161 │ └─ Images / raster work → PyMuPDF/fitz
162 │
163 ├─ Modify existing PDF?
164 │ ├─ Add text/images → pdf-lib (Node)
165 │ ├─ Merge/split/rotate/scrub → pypdf + scripts
166 │ ├─ Fill forms → pdf-lib
167 │ └─ Sign → pyHanko
168 │
169 └─ Batch processing?
170 └─ OCRmyPDF / pypdf / pdfplumber pipeline
171```
172
173---
174
175## Do / Avoid (Jul 2026)
176
177### Do
178
179- Keep a versioned source document (doc/slide/design file) alongside the PDF.
180- Verify links and reading order for long documents.
181- Use real redaction and test by copy/paste.
182- Use `OCRmyPDF` for scanned PDFs before text extraction.
183- Scrub all metadata layers before distribution (PDF-internal, filesystem dates, macOS xattrs).
184- Verify with `exiftool -all -G1` after scrubbing — check for tool fingerprints (XMP Toolkit) and residual dates.
185- Confirm PyMuPDF's AGPL/commercial licensing fits the deployment before relying on it in closed-source or SaaS code paths.
186
187### Avoid
188
189- Editing PDFs as the primary workflow when a source doc exists.
190- Defaulting to `wkhtmltopdf` in new 2026 workflows.
191- Shipping PDFs with broken links or illegible charts.
192- Including customer PII or secrets in PDFs without explicit approval.
193- Scrubbing only PDF-internal metadata while ignoring filesystem dates and OS-level xattrs.
194- Using exiftool to modify PDF XMP without overwriting its `XMP Toolkit` fingerprint.
195- Trusting `Camelot`/`pdfplumber` table output on financial or legal documents without a visual spot-check or accuracy-score review — misaligned columns fail silently.
196- Bundling PyMuPDF into a proprietary product without checking AGPL obligations or budgeting for a commercial license.
197
198## What Good Looks Like
199
200- Fidelity: export is reproducible from a versioned source file (doc/slide/design) and looks identical across viewers.
201- Accessibility: tags/reading order are correct; links work; scanned docs are OCRed when appropriate.
202- Release hygiene: file naming includes version/date; metadata is clean; no “PDF as source of truth”.
203- Security: redaction is verified (copy/paste test) and sensitive data is minimized.
204- QA: release checklist completed using `assets/pdf-release-checklist.md`.
205
206## Optional: AI / Automation
207
208Use only when explicitly requested and policy-compliant.
209
210- Generate a release checklist run; humans verify the final PDF manually.
211
212## Navigation
213
214**Resources**
215- [references/pdf-generation-patterns.md](references/pdf-generation-patterns.md) — Complex layouts, multi-page docs
216- [references/pdf-extraction-patterns.md](references/pdf-extraction-patterns.md) — Text, table, image extraction
217- [references/pdf-accessibility-compliance.md](references/pdf-accessibility-compliance.md) — Tagged PDFs, PDF/UA, EAA compliance
218- [references/pdf-forms-interactive.md](references/pdf-forms-interactive.md) — AcroForms, form filling, digital signatures
219- [references/pdf-security-redaction.md](references/pdf-security-redaction.md) — Encryption, permissions, real redaction
220- [data/sources.json](data/sources.json) — Library documentation links
221
222**Scripts**
223- `scripts/merge_pdfs.py` — Merge PDFs in order
224- `scripts/split_pdf.py` — Split one-per-page or by range
225- `scripts/rotate_pdf.py` — Rotate all pages by 90/180/270 degrees
226- `scripts/scrub_metadata.py` — Scrub Info/XMP metadata, attachments, JavaScript, and thumbnails
227
228**Templates**
229- [assets/invoice-template.md](assets/invoice-template.md) — Invoice PDF generation
230- [assets/report-template.md](assets/report-template.md) — Multi-page report structure
231- [assets/pdf-release-checklist.md](assets/pdf-release-checklist.md) — Links, accessibility, export fidelity
232
233**Related Skills**
234- [../document-docx/SKILL.md](../document-docx/SKILL.md) — Word document generation
235- [../document-xlsx/SKILL.md](../document-xlsx/SKILL.md) — Excel/spreadsheet workflows
236- [../document-pptx/SKILL.md](../document-pptx/SKILL.md) — PowerPoint presentations
237
238## Fact-Checking
239
240- Use web search/web fetch to verify current external facts, versions, pricing, deadlines, regulations, or platform behavior before final answers.
241- Prefer primary sources; report source links and dates for volatile information.
242- If web access is unavailable, state the limitation and mark guidance as unverified.
243
244## Learnings Loop
245
246Before applying this skill on a non-trivial task, read `learnings.consolidated.md` in this directory (and `learnings.md` if present).
247
248After applying it, if you encountered a pattern worth remembering, a mistake worth preventing, or a domain fact that surprised you, append one dated bullet to `learnings.md` via `agents-skills-feedback-loop/scripts/append_learning.py`. Do not modify `SKILL.md` itself.
249