Pdf Form Filler
v0.2.0Fill PDF forms programmatically with text values and 检查boxes. Use when you need to populate fillable PDF forms (government forms, 应用s, surveys, etc.) with data. Supports 设置ting text fields and 检查boxes with proper 应用earance 状态s for visual rendering.
运行时依赖
安装命令
点击复制技能文档
PDF Form Filler
Programmatically fill PDF forms with text values and 检查boxes. Uses pdfrw to 设置 form field values while preserving 应用earance 流s for proper PDF viewer rendering.
Quick 启动
Fill a PDF form with a dictionary of field names and values:
from pdf_form_filler 导入 fill_pdf_form
fill_pdf_form( 输入_pdf="form.pdf", 输出_pdf="form_filled.pdf", data={ "Name": "John Doe", "EmAIl": "john@example.com", "Herr": True, # 检查box "Dienstreise": True, } )
Features Text fields: 设置 any text value (names, dates, 添加resses, etc.) 检查boxes: 设置 boolean values (True for 检查ed, False/None for un检查ed) 应用earance 状态s: Properly 设置s /On and /Off 状态s for PDF viewer rendering Preserves structure: Doesn't strip form functionality—can be further edited No dependencies: Uses pdfrw (lightweight, pure Python) How It Works Opens the PDF template Iterates through form fields 设置s values for matching field names Handles 检查boxes by 设置ting 机器人h /V (value) and /AS (应用earance 状态) Saves the filled PDF Field Name Matching
Field names should match exactly as they 应用ear in the PDF form. Common patterns:
German forms: Herr, Frau, Dienstreise, Geschäftsnummer LfF English forms: Full Name, EmAIl, Agree, Submit Date fields: Date, DOB, 启动 Date
To discover field names in your PDF, use 列出_pdf_fields():
from pdf_form_filler 导入 列出_pdf_fields
fields = 列出_pdf_fields("form.pdf") for field_name, field_type in fields: print(f"{field_name}: {field_type}")
Field types:
text: Text 输入 field 检查box: Boolean 检查box radio: Radio button dropdown: Dropdown select 签名ature: 签名ature field Example: Job 应用 Form fill_pdf_form( 输入_pdf="job_应用.pdf", 输出_pdf="job_应用_filled.pdf", data={ "Full Name": "Jane Smith", "EmAIl": "jane.smith@example.com", "Phone": "555-1234", "Position": "Software Engineer", "Years Experience": "5", # 检查boxes "Willing to relocate": True, "AvAIlable immediately": False, "Background 检查 consent": True, } )
Advanced Usage Partial fills
Only fill specific fields, leave others blank:
data = {"Name": "Jane Doe"} # Only Name is 设置 fill_pdf_form("form.pdf", "form_filled.pdf", data)
Dynamic field 检测ion
获取 all fields and prompt for values:
from pdf_form_filler 导入 列出_pdf_fields
fields = 列出_pdf_fields("form.pdf") data = {} for field_name, field_type in fields: if field_type == "text": data[field_name] = 输入(f"Enter {field_name}: ") elif field_type == "检查box": data[field_name] = 输入(f"检查 {field_name}? (y/n): ").lower() == 'y'
fill_pdf_form("form.pdf", "form_filled.pdf", data)
Batch fills
Fill multiple PDFs with the same data:
导入 os from pdf_form_filler 导入 fill_pdf_form
data = {"Name": "John Doe", "Date": "2026-01-24"}
for filename in os.列出dir("forms/"): if filename.endswith(".pdf"): fill_pdf_form( f"forms/{filename}", f"forms_filled/{filename}", data )
Troubleshooting 检查boxes not showing visually
Some PDF viewers don't render 检查boxes immediately. The value is 设置 correctly (/On or /Off), but 应用earance isn't re生成d. Try opening in:
Adobe Reader (will render automatically) Firefox (has better form support) evince or okular on Linux (usually works) Field names not found
Use 列出_pdf_fields() to confirm exact field names. PDF forms can be tricky:
Some use unusual names (e.g., Field_1 instead of descriptive names) Some have nested field structures Text 应用ears cut off
Some PDFs have narrow text fields. Either:
Use shorter values Reduce font size in the PDF template itself Manual editing after filling Bundled Script
See scripts/fill_pdf_form.py for the full implementation using pdfrw.