Pdf form filler
Skill cxcscmu/SkillLearnBench/skills/b4-skill-creator-claude-opus-4-6/court-form-filling/pdf-form-filler
Fill PDF form fields programmatically using Python and pypdf. Use this skill whenever the user needs to fill out a PDF form, set text fields, or check checkboxes in a PDF document.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill pdf-form-fillerAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
2.0 KB, 460 tokens by cl100k_base, as published. Nobody here has run it
PDF Form Filler
Fill PDF forms using pypdf (available in the environment).
Workflow
- Extract field names: Read the PDF and list all form fields with their full hierarchical paths
- Identify field types:
/Tx= text field,/Btn= checkbox/button - Map data to fields: Match user-provided data to the correct field paths
- Fill and save: Use
pypdf.PdfWriterto write values
Key Code Pattern
import pypdf
reader = pypdf.PdfReader("input.pdf")
writer = pypdf.PdfWriter()
writer.append(reader)
# Fill text fields - use the SHORT field name (leaf), not full path
# writer.update_page_form_field_values(writer.pages[page_idx], {"FieldName[0]": "value"})
# For checkboxes, update the annotation directly:
# Find the annotation on the page, then set /V and /AS to the checked state
for page in writer.pages:
for annot in page.get("/Annots", []):
obj = annot.get_object()
if obj.get("/T") == "CheckboxName[0]":
obj.update({
pypdf.generic.NameObject("/V"): pypdf.generic.NameObject("/1"),
pypdf.generic.NameObject("/AS"): pypdf.generic.NameObject("/1"),
})
writer.write("output.pdf")
Checkbox States
- Check the
/AP->/Ndictionary for valid appearance states (e.g.,/1,/2,/Off) - Set both
/Vand/ASto the desired state /Offtypically means unchecked
Tips
- Field names in annotations use the SHORT leaf name (e.g.,
PlaintiffName1[0]), not the full hierarchical path update_page_form_field_valuesworks for text fields on a specific page- For checkboxes, iterate annotations and update directly
- Some PDFs have duplicate field names across pages (e.g.,
Plaintiff[0]on pages 2, 3, 4) - handle each page separately
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.