Skip to content

Open source CapCut alternative.

TypeScript

feat(app): teach the pdf skill to fill forms headlessly

David Le497c72092faa
diff --git a/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/documents/SKILL.md b/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/documents/SKILL.md
index d5a99f5e..7b745cc1 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/documents/SKILL.md
+++ b/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/documents/SKILL.md
@@ -31,7 +31,7 @@ Preview has no useful AppleScript dictionary. Open files with `open`, do file-le
## In-Preview actions (keyboard, after focusing Preview)
- Rotate right/left: Cmd+R / Cmd+L. Select all text: Cmd+A. Copy selection: Cmd+C (then `pbpaste` to read it).
-- PDF form fields: press Tab to move to the first/next fillable field, then type with text.enter.
+- PDF form fields: press Tab to move to the first/next fillable field, then type with text.enter. This is the visual path; to fill a form headlessly (no Preview), use the `pdf` skill's `pdf-fill` instead.
- Export/Save As has no shortcut: use ax.observe on the menu bar (File → Export as PDF…) and click the menu items.
## Verify
diff --git a/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/pdf/SKILL.md b/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/pdf/SKILL.md
index 2cabbfa9..a75cf85d 100644
--- a/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/pdf/SKILL.md
+++ b/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/pdf/SKILL.md
@@ -1,15 +1,15 @@
# PDF
id: pdf
-description: Expert headless PDF and document work — extract text and structured data with liteparse, merge/split/rotate with qpdf, and convert document formats with textutil.
-tags: pdf, document, convert, merge, split, ocr, extract
-keywords: pdf, extract, parse, text, ocr, scan, json, merge, combine, split, extract pages, rotate, convert, docx, rtf, html
+description: Expert headless PDF and document work — extract text and structured data with liteparse, fill forms with pdf-fill, merge/split/rotate with qpdf, and convert document formats with textutil.
+tags: pdf, document, convert, merge, split, ocr, extract, fill, form
+keywords: pdf, extract, parse, text, ocr, scan, json, merge, combine, split, extract pages, rotate, convert, docx, rtf, html, fill, form, fillable, acroform, checkbox
tools: shell_exec
-`lit` (liteparse) and `qpdf` are bundled and on the PATH; `textutil` and `mdls`
-ship with macOS. This is the headless path — for interactive Preview work
-(filling a form, watching a rotation), use the `documents` skill instead.
-Creating files is reversible (consent gate).
+`lit` (liteparse), `pdf-fill`, and `qpdf` are bundled and on the PATH; `textutil`
+and `mdls` ship with macOS. This is the headless path — fill a form right here with
+`pdf-fill`; only drop to the `documents` skill when the user wants to watch it
+happen in Preview. Creating files is reversible (consent gate).
## qpdf — structure (page order in, page order out)
- Merge: `qpdf --empty --pages a.pdf b.pdf -- out.pdf`.
@@ -30,5 +30,14 @@ Creating files is reversible (consent gate).
- Skip OCR for a known-digital PDF to go faster: `lit parse in.pdf --no-ocr`.
- For just a title/metadata lookup without parsing, `mdls -name kMDItemTitle in.pdf` still works.
+## Fill a PDF form — use pdf-fill (`pdf-fill`)
+`pdf-fill` writes a NEW file; it never edits in place. All I/O is JSON. Start by asking it what kind of form this is:
+- `pdf-fill list in.pdf` lists the fillable (AcroForm) fields: `{name, type, value, page, rect}`.
+- **Has fields (non-empty list) → set them.** Build a `{fieldName: value}` map and pipe it in: `echo '{"FullName":"Ada","Agree":true}' | pdf-fill set in.pdf --data - -o out.pdf`. Text and dropdown fields take strings; checkboxes take `true`/`false`. The result reports `applied` and `missing` so you can see any name that did not match.
+- **No fields (empty list) → it is a flat or scanned form; overlay text by position.** Get the labels and their boxes with `lit parse in.pdf --format json`, then stamp values next to them: `echo '[{"page":0,"x":120,"y":700,"text":"Ada Lovelace","size":12}]' | pdf-fill overlay in.pdf --data - -o out.pdf`. Coordinates are PDF points from the BOTTOM-left; lit boxes are top-left, so convert with the page height from `pdf-fill pages in.pdf` (`y_pdf = height - y_top - h`).
+- To make the result non-editable (e.g. before sending it on), `pdf-fill flatten out.pdf -o final.pdf` burns the values into the page.
+- Ask the user for any value you do not have before filling; do not invent field contents.
+
## Verify
-- After a structural edit, confirm with `qpdf --show-npages out.pdf` or re-read the text with `mdls`. After a conversion, confirm the output file exists and opens.
\ No newline at end of file
+- After a structural edit, confirm with `qpdf --show-npages out.pdf` or re-read the text with `mdls`. After a conversion, confirm the output file exists and opens.
+- After filling, re-run `pdf-fill list out.pdf` and check the values are present (for an overlay, flatten then `lit parse` the result).
\ No newline at end of file