Create, read, merge, fill, and secure PDF files.
Skill metadata
| Source | Bundled (installed by default) |
| Path | skills/productivity/pdf |
| Version | 1.0.0 |
| Author | Nous Research |
| License | MIT |
| Platforms | linux, macos, windows |
| Tags | pdf, documents, forms, reportlab, pypdf, pdfplumber |
| Related skills | docx, xlsx, powerpoint, ocr-and-documents |
Reference: full SKILL.md
The following is the complete skill definition that Hermes loads when this skill is triggered. This is what the agent sees as instructions when the skill is active.
PDF Skill
Create PDFs from structured specs, build and fill AcroForm forms (with layout linting and visual overlays), extract text/tables/metadata, merge/split/rotate/watermark/stamp pages, export page images, manage metadata and attachments, and encrypt/decrypt — using pypdf, reportlab, and pdfplumber. Scanned (image-only) PDFs contain no text layer: OCR is explicitly out of scope here — when a page is image-only, stop and use the ocr-and-documents skill instead of pretending to extract text.
When to Use
- Generate a report, invoice, or multi-page document as PDF.
- Build a fillable AcroForm (text/checkbox/radio/dropdown) from a JSON spec, linting the layout first.
- Pull text, tables (JSON/CSV), metadata, or form-field values out of a PDF.
- Merge, split, rotate, extract page subsets, watermark, stamp text/images at coordinates, bookmark, or compress PDFs.
- Export pages as PNGs for visual review or for OCR hand-off; set/clear document metadata; add/extract file attachments.
- Fill or flatten AcroForm forms; encrypt or decrypt with passwords.
- NOT for scanned/image-only PDFs (use
ocr-and-documents) and NOT for pixel-perfect HTML-to-PDF rendering (use a headless browser).
Prerequisites
- Python 3.10+ with
pypdf,reportlab,pdfplumber:python -m pip install pypdf reportlab pdfplumber - Optional, for page rasterization (
pdf_page_image.py, overlay rendering):python -m pip install pypdfium2, or poppler'spdftoppmon PATH. Scripts fall back pypdfium2 → pdftoppm and report{"rendered": false, "missing": [...]}(exit 0) when neither exists. - Each helper script checks imports lazily and prints an install hint if a dependency is missing.
How to Run
All helpers live in scripts/ and are argparse CLIs — run them with the terminal tool; every one supports --help. They read/write JSON strictly as UTF-8, print JSON results to stdout, and exit non-zero on failure.
python scripts/pdf_create.py spec.json -o out.pdf # build PDF from JSON spec
python scripts/pdf_make_form.py formspec.json -o form.pdf # build fillable AcroForm from JSON spec
python scripts/pdf_form_layout.py formspec.json # lint form layout BEFORE building
python scripts/pdf_form_layout.py formspec.json --render-overlay boxes.png [--pdf form.pdf]
python scripts/pdf_read.py doc.pdf --text # per-page text (JSON)
python scripts/pdf_read.py doc.pdf --tables --csv-dir t/ # tables to JSON + CSV files
python scripts/pdf_read.py doc.pdf --meta # metadata, page sizes, encrypted/scanned flags
python scripts/pdf_read.py form.pdf --fields # form fields: name, type, value
python scripts/pdf_merge.py a.pdf b.pdf -o merged.pdf [--bookmarks]
python scripts/pdf_split.py doc.pdf --pages 1-3,7 -o part.pdf [--rotate 90]
python scripts/pdf_fill_form.py form.pdf --fields-json values.json -o filled.pdf [--flatten]
python scripts/pdf_secure.py doc.pdf --encrypt -o enc.pdf --user-password your-password
python scripts/pdf_secure.py enc.pdf --decrypt -o dec.pdf --password your-password
python scripts/pdf_watermark.py doc.pdf --stamp mark.pdf -o stamped.pdf [--under]
python scripts/pdf_stamp.py doc.pdf -o out.pdf --text "DRAFT" --x 150 --y 400 \
--font-size 60 --rotation 45 --opacity 0.3 --color "#cc0000" [--pages 1-3]
python scripts/pdf_stamp.py doc.pdf -o out.pdf --image sig.png --x 400 --y 60 --width 120
python scripts/pdf_page_image.py doc.pdf --pages 1-3 --dpi 150 --out-dir imgs/
python scripts/pdf_meta.py doc.pdf --set-meta --title "T" --author "A" -o out.pdf
python scripts/pdf_meta.py doc.pdf --attach data.csv -o out.pdf
python scripts/pdf_meta.py doc.pdf --list-attachments | --extract-attachments dir/
Quick Reference
| Task | Tool | Command / API |
|---|---|---|
| Create doc (headings, tables, images) | reportlab platypus | pdf_create.py spec.json -o out.pdf |
| Build fillable form | reportlab acroForm | pdf_make_form.py formspec.json -o form.pdf |
| Lint form layout / overlay image | pure python + PIL | pdf_form_layout.py formspec.json [--render-overlay o.png] |
| Per-page text | pdfplumber | pdf_read.py f.pdf --text |
| Tables → JSON/CSV | pdfplumber | pdf_read.py f.pdf --tables |
| Metadata / sizes / encrypted / scanned | pypdf + pdfplumber | pdf_read.py f.pdf --meta |
| Merge (+ outline) | pypdf | pdf_merge.py a.pdf b.pdf -o m.pdf |
| Split / extract / rotate | pypdf | pdf_split.py f.pdf --pages 2-5 --rotate 90 |
| List / fill / flatten form | pypdf | pdf_read.py --fields, pdf_fill_form.py |
| Encrypt / decrypt (AES-256) | pypdf | pdf_secure.py --encrypt/--decrypt |
| Watermark / stamp PDF page | pypdf | pdf_watermark.py f.pdf --stamp w.pdf |
| Stamp text/image at coordinates | reportlab + pypdf | pdf_stamp.py f.pdf --text "Sign here" --x 400 --y 60 |
| Pages → PNG (review / OCR hand-off) | pypdfium2 or pdftoppm | pdf_page_image.py f.pdf --pages 1-3 --out-dir imgs/ |
| Set/clear metadata, attachments | pypdf | pdf_meta.py --set-meta / --attach / --extract-attachments |
| Compress content streams | pypdf | pdf_split.py f.pdf --pages 1-N --compress |
Procedure
- Inspect first. Run
pdf_read.py file.pdf --meta. Checkencrypted(if true, decrypt first withpdf_secure.py --decrypt) andlikely_scanned_pages. If pages are image-only, export them withpdf_page_image.py --pages <scanned> --dpi 300 --out-dir imgs/and hand the PNGs to theocr-and-documentsskill — do not report empty text as "no content". - Create. Write a JSON spec with
write_file(elements:heading,paragraph,table,image,pagebreak; optionaltitle/authormetadata; page numbers are added automatically), then runpdf_create.py. Verify visually withvision_analyzeon a rendered page image if layout matters. - Extract.
--textgives a JSON list of per-page strings;--tablesgives row arrays per page and can also emit CSV files. Read results withread_file; never eyeball a binary PDF directly. - Manipulate.
pdf_merge.pyconcatenates and can add one bookmark per source file;pdf_split.pyhandles page ranges (1-based, e.g.1-3,5,9-), rotation in 90° steps, and--compress. Watermark by preparing a single-page stamp PDF (e.g. viapdf_create.py) and overlaying it withpdf_watermark.py; for one-liner stamps ("sign here", diagonal DRAFT, corner labels) usepdf_stamp.pywith text or an image at explicit coordinates. - Build forms. Write one form-spec JSON (fields with
label_box/entry_boxin PDF points — seereferences/forms.md), lint it withpdf_form_layout.pyand fix every reported problem, optionally review the--render-overlayPNG withvision_analyze, then build withpdf_make_form.pyand confirm withpdf_read.py --fields. - Fill forms. List fields (
--fields) to learn exact names and types, write a UTF-8 JSON of{"FieldName": "value"}withwrite_file(checkboxes accepttrue/false; radio/choice values must match the field's export options), thenpdf_fill_form.py. Re-read with--fieldsto confirm values landed. - Metadata & attachments.
pdf_meta.py --set-metawrites Title/Author/Subject/Keywords (DocInfo);--clear-metadrops them;--attach/--list-attachments/--extract-attachmentsround-trip embedded files. - Secure. Encrypt with distinct user/owner passwords and AES-256. To remove a password you know,
--decryptwrites an unencrypted copy. - Verify (see below) before reporting success.
Pitfalls
- Scanned PDFs: empty
extract_text()plus page images means there is no text layer. Route toocr-and-documents; do not fabricate text. - Flattening limits:
pdf_fill_form.py --flattenuses pypdf's flatten support, which converts widget appearances into page content. It is reliable for plain text fields and checkboxes but can drop or misrender exotic widgets (rich text, custom appearance streams, some radio groups). Verify the flattened output visually withvision_analyze; for bulletproof flattening use an external renderer (e.g. Ghostscript orpdftoppm+reassembly) as a fallback. - NeedAppearances: after filling, viewers only render values if appearance streams exist. The fill script sets the AcroForm
NeedAppearancesflag so conforming viewers regenerate them; some minimal viewers ignore it — flatten if display fidelity matters. - Non-Latin form values: values are stored correctly (UTF-16), but the field's default font may lack glyphs, so a viewer can show blanks even though the data round-trips. Verify with
--fields, not just visually. - Compression expectations:
--compressonly deflates content streams. Typical savings are 0–20%; it does nothing for PDFs dominated by images or already-compressed streams. It is not a substitute for image downsampling (Ghostscript territory). - Permission flags don't enforce: owner-password permission bits (no-print, no-copy) are polite requests that viewers may honor; any library (including pypdf) can read and strip them. Only the user password actually gates content via encryption. Never present permission flags as security.
- Table extraction is heuristic: pdfplumber detects tables from ruling lines/word alignment; borderless or merged-cell tables may need
table_settingstuning or manual cleanup. - Page indexing: helper CLIs take 1-based pages; pypdf APIs are 0-based. The scripts convert — don't double-convert.
- Rotated stamp text extraction: pdfplumber's line grouping scrambles rotated glyphs (a 45° "DRAFT" extracts as stray letters); verify rotated stamps with
pypdf'sextract_text()or a rendered image instead. - Radio groups: reportlab needs ≥2
radio()widgets per group, fills need the slashed export value ("/red"), and flatten fidelity is worst for radios — seereferences/forms.md. - Metadata scope:
pdf_meta.pywrites the classic DocInfo dictionary only; embedded XMP metadata (if any) is left untouched and may show different values in some viewers. - PDF/A is out of scope: pypdf/reportlab cannot produce or validate conformant PDF/A. If archival conformance is required, run Ghostscript via the
terminaltool (e.g.gs -dPDFA=2 -dPDFACompatibilityPolicy=1 -sColorConversionStrategy=UseDeviceIndependentColor -sDEVICE=pdfwrite -o out.pdf in.pdfwith a suitable ICC profile) and validate with veraPDF — both are external installs, and the result still needs validation, not assumption. - Rotation must be a multiple of 90; encrypted inputs must be decrypted before any other operation.
Verification
- After create/merge/split:
pdf_read.py out.pdf --meta— confirmpage_count, and per-pagerotationwhen you rotated. - After extraction: check the JSON is non-empty and spot-check a known string or cell.
- Form design loop:
pdf_form_layout.py spec.jsonmust exit 0; then--render-overlay boxes.png --pdf form.pdfand review the PNG withvision_analyze(red = entry boxes with field names, blue = label boxes) asking about overlaps, misalignment, and labels detached from their fields. Iterate spec → lint → overlay until clean. - After building a form:
pdf_read.py form.pdf --fieldslists every spec field with the right type and options. - After form fill:
pdf_read.py filled.pdf --fieldsand compare values (exact match, including non-ASCII). - After stamping: re-extract text (pypdf for rotated stamps) or render the page with
pdf_page_image.pyand inspect withvision_analyze. - After metadata/attachment edits:
pdf_read.py --meta/pdf_meta.py --list-attachments, and re-extract an attachment to byte-compare. - After encrypt:
--metashows"encrypted": trueand opening without a password fails; after decrypt, text extraction matches the original. - For anything visual (watermarks, flattened forms), render and inspect with
vision_analyze.