Run3 Extract PDF Form Field Names
[COLM'26] SkillLearnBench is the first benchmark for evaluating continual learning methods that automatically generate agent skills.
npx -y skills add cxcscmu/SkillLearnBench --skill run3_Extract-PDF-Form-Field-NamesAssembled 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
Use this skill first to discover the actual field names in a PDF form. Extracts and prints all form field names from a PDF file to ensure accurate field mapping before filling the form.
SKILL.md
2.0 KB, as published. Nobody here has run it
Extract PDF Form Field Names
Purpose
Discover the exact field names in a PDF form before attempting to fill it. This prevents mapping errors and field-not-found issues.
Implementation
import pdfrw
def extract_pdf_field_names(pdf_path):
"""
Extract all form field names from a PDF.
Args:
pdf_path: Path to the PDF file
Returns:
List of field names
"""
template = pdfrw.PdfReader(pdf_path)
field_names = []
if template.Root.AcroForm is None:
print("No form fields found in PDF")
return field_names
for page in template.pages:
annotations = page.get("/Annots")
if annotations:
for annotation in annotations:
if annotation["/Subtype"] == "/Widget":
field_name = annotation["/T"]
if field_name:
# Remove parentheses that pdfrw adds
clean_name = field_name[1:-1] if field_name.startswith('(') else field_name
field_names.append(clean_name)
print(f"Field found: {clean_name}")
return field_names
# Run extraction
pdf_path = "/root/sc100-blank.pdf"
fields = extract_pdf_field_names(pdf_path)
print(f"\nTotal fields found: {len(fields)}")
Steps
- Load the PDF using pdfrw
- Check if form exists in Root.AcroForm
- Iterate through all pages and annotations
- Extract field names from Widget annotations
- Clean field names (remove parentheses added by pdfrw)
- Print each field name for verification
- Use the printed names for accurate field mapping
Notes
- Run this skill BEFORE attempting to fill the form
- Document all field names printed to ensure mapping accuracy
- Field names are case-sensitive