Pdf form filling
Skill cxcscmu/SkillLearnBench/skills/b1-one-shot-claude-haiku-4-5/court-form-filling/pdf-form-filling
[COLM'26] SkillLearnBench is the first benchmark for evaluating continual learning methods that automatically generate agent skills.
npx -y skills add cxcscmu/SkillLearnBench --skill pdf-form-fillingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
What its author says it does
Copied from the file, not written here
Fill PDF form fields programmatically using Python libraries like pypdf or pdfrw
SKILL.md
2.6 KB, as published. Nobody here has run it
PDF Form Filling with Python
Overview
This skill covers how to identify and fill form fields in PDF documents, particularly for legal forms like court documents.
Key Libraries
1. PyPDF (pypdf)
- Modern, actively maintained library for PDF manipulation
- Can read form field names and fill them
- Installation:
pip install pypdf
2. pdfrw
- Lightweight alternative, good for form filling
- Installation:
pip install pdfrw
Common Workflow
With pypdf:
from pypdf import PdfReader, PdfWriter
# Read the blank form
reader = PdfReader("/path/to/form.pdf")
writer = PdfWriter()
# Get the form fields
fields = reader.get_fields()
print(fields.keys()) # See all available fields
# Create a copy and update fields
for page in reader.pages:
writer.add_page(page)
# Update fields
writer.update_page_form_field_values(
writer.pages[0],
{
"Field1": "Value1",
"Field2": "Value2",
}
)
# Save the result
with open("/path/to/filled.pdf", "wb") as f:
writer.write(f)
With pdfrw:
from pdfrw import PdfReader, PdfWriter, PdfDict, PdfObject
# Read template
template = PdfReader("/path/to/form.pdf")
# Inspect available fields
for field in template.Root.AcroForm.Fields:
print(field.T) # Field name
# Fill fields
for field in template.Root.AcroForm.Fields:
if field.T == "FieldName":
field.V = "Field Value"
field.AP = None # Clear appearance stream
# Write output
PdfWriter().write("/path/to/filled.pdf", template)
Inspecting Form Fields
from pypdf import PdfReader
reader = PdfReader("form.pdf")
fields = reader.get_fields()
for field_name, field_data in fields.items():
print(f"{field_name}: {field_data}")
Important Notes
- Form field names are case-sensitive
- Some PDFs have checkboxes/radio buttons requiring "Yes"/"No" or specific values
- Date fields may need specific formatting
- Always check field types before filling
- Keep a copy of the blank form for reference
California Court Forms Specifics
California court forms often use:
- Multi-page layouts with page numbers
- Standard field naming conventions
- Checkboxes for yes/no selections
- Date fields in specific formats
- Signature/initial areas (typically left blank)
When filling:
- Always read the form first to understand field names
- Map case data to appropriate fields
- Leave court-filled sections empty (dates, case numbers, judge info)
- Preserve form formatting