pdf-form-filling
Methods for programmatically filling PDF forms (AcroForms) and saving the results using pypdf.
- License 许可
- MIT
- 最近更新
- 2026-10-02
- Stars
- ★ 93
- Forks
- 8
01 前言 Front Matter
- name
- pdf-form-filling
- description
- Methods for programmatically filling PDF forms (AcroForms) and saving the results using pypdf.
03 SKILL.md 正文
PDF Form Filling Skill
This skill covers how to fill out AcroForms in a PDF document using pypdf.
Prerequisites
- Python 3.x
pypdflibrary (pip install pypdf)
Usage Patterns
Filling Text Fields and Checkboxes
from pypdf import PdfReader, PdfWriter
def fill_pdf(input_pdf_path, output_pdf_path, data_dict):
reader = PdfReader(input_pdf_path)
writer = PdfWriter()
for page in reader.pages:
writer.add_page(page)
# Fill form fields
writer.update_page_form_field_values(writer.pages[0], data_dict)
# Note: If fields span multiple pages, you might need to iterate
# through writer.pages and apply relevant parts of data_dict.
# However, writer.update_page_form_field_values can often find the fields
# globally if they are properly indexed.
with open(output_pdf_path, "wb") as output_stream:
writer.write(output_stream)
# Example data_dict
# For text fields: {"field_name": "Value"}
# For checkboxes: {"checkbox_name": "/Yes"} or similar
data = {
"full_name": "John Doe",
"is_citizen": "/Yes"
}
fill_pdf("blank.pdf", "filled.pdf", data)
Important Considerations
- Field Naming: Use the full hierarchical name found during inspection (e.g.,
SC-100[0].Page1[0].Field[0]). - Appearance Streams: Some PDF readers might not show the filled value until you click on the field unless
/NeedAppearancesis set to true in the PDF's Interactive Form Dictionary.pypdfhandles basic filling, but complex forms might need flattening or specific appearance settings. - Checkboxes: Checkbox values are typically
/Yes(or other export value) and/Off.
04 同仓库更多 Skills
object_counter
Count occurrences of an object in the image using computer vision algorithm.
travel-planning-workflow
Invoke this skill when performing travel planning. It defines a structured workflow for generating itineraries. Following this workflow is essential to ensure the final plan satisfies user requirements.
bundled-dataset-search-tool
invoke this skill when you need to perform database search for travel planning. This skill provides some useful pre-packaged tools to look up accommodations, attractions, cities, driving distance, flights, and restaurants from the bundled dataset.
glm-output
Output-processing guidance for GLM tasks. Especially useful after glm-basics and glm-calibration when you need verifier-matching metrics from output.nc and a final /root/metrics.json.
glm-calibration
Calibration guidance for GLM tasks. Often most effective after glm-basics has clarified the setup; glm-output is the companion skill for exact final metric computation.
glm-basics
A good starting point for GLM calibration tasks. Use to inspect glm3.nml, confirm how GLM runs, and identify the relevant files before moving on to calibration and output evaluation.