| name | pdf |
| description | Read, extract text, fill forms, and overlay text on PDF files using pdftk and pdfjs-dist. Use when working with PDFs — extracting content, filling fillable form fields, or adding text to non-fillable PDFs via coordinate-based overlays. Handles insurance forms, applications, contracts, and any PDF document processing. |
PDF Skill
Dependencies
pdftk — PDF toolkit for form operations, stamping, merging, splitting
pdfjs-dist — Mozilla's PDF.js for text extraction (npm, already installed)
google-chrome — Available at /usr/bin/google-chrome for generating overlay PDFs from HTML
Note: pdfjs-dist text extraction returns empty for scanned/image-based PDFs. For those, burst into individual pages with pdftk and view in the browser to read content visually.
Quick Reference
Extract text from a PDF
node /home/jenn/clawd/skills/pdf/scripts/pdf-extract.js <file.pdf>
List fillable form fields
pdftk <file.pdf> dump_data_fields
Fill a fillable PDF form
Create an FDF file with field values, then:
pdftk <form.pdf> fill_form <data.fdf> output <filled.pdf> flatten
To generate a blank FDF template from a form:
pdftk <form.pdf> generate_fdf output <template.fdf>
Edit the FDF template, setting /V values for each field. For text fields use /V (value). For buttons/checkboxes use /V /OptionName. For Choice/dropdown fields use /V (OptionText) matching one of the FieldStateOption values.
Important: Always use generate_fdf first to get the template, then edit the copy. Hand-crafted FDF files may fail to parse — pdftk is picky about the format (needs the binary header bytes from the template).
Overlay text on non-fillable PDFs
For PDFs without form fields, generate an HTML overlay and stamp it:
- Create an HTML file with absolutely positioned text matching PDF coordinates
- Convert to PDF using Chrome:
google-chrome --headless --disable-gpu --print-to-pdf=overlay.pdf --no-margins overlay.html
- Stamp onto original:
pdftk original.pdf multistamp overlay.pdf output filled.pdf
Use scripts/pdf-overlay.js to generate the overlay HTML:
node /home/jenn/clawd/skills/pdf/scripts/pdf-overlay.js <config.json> <output.html>
The config.json format (totalPages must match the source PDF page count for multistamp to work correctly):
{
"pageWidth": 612,
"pageHeight": 792,
"totalPages": 7,
"pages": [
{
"page": 1,
"fields": [
{"x": 200, "y": 150, "text": "Boardwise", "fontSize": 10},
{"x": 200, "y": 175, "text": "123 Main St", "fontSize": 10}
]
Coordinates are in PDF points (72 points = 1 inch). Origin is top-left.
To find the right coordinates, screenshot the PDF page and estimate positions based on the layout, or use scripts/pdf-coords.js to get text positions from the existing PDF as reference points.
Reading scanned/image PDFs
When pdf-extract.js returns empty pages, the PDF contains scanned images, not text. To read:
- Burst into individual pages:
pdftk input.pdf burst output page_%02d.pdf
- Open each page in the browser (openclaw profile) and screenshot to read visually
- Zoom out with
document.body.style.zoom = '0.35' to see full page in Chrome PDF viewer
Fillable form workflow (end-to-end)
pdftk form.pdf dump_data_fields
pdftk form.pdf generate_fdf output template.fdf
cp template.fdf filled.fdf
pdftk form.pdf fill_form filled.fdf output filled.pdf
pdftk form.pdf fill_form filled.fdf output filled.pdf flatten
Other pdftk operations
pdftk a.pdf b.pdf cat output merged.pdf
pdftk input.pdf cat 1-3 output pages1-3.pdf
pdftk input.pdf cat 1-endeast output rotated.pdf
pdftk input.pdf dump_data
pdftk input.pdf output protected.pdf owner_pw secret
pdftk protected.pdf input_pw secret output unlocked.pdf
pdftk input.pdf stamp overlay.pdf output stamped.pdf
pdftk input.pdf multistamp overlay.pdf output stamped.pdf
pdftk input.pdf burst output page_%02d.pdf