fill_pdf_form
Fills a PDF form with provided data. It maps field keys to their respective pages and applies values. It handles multi-line text areas by assigning specific strings to the identified sequential keys. For checkboxes, it uses the precise export values found during inspection. All dates must be formatted as 'xxxx-xx-xx'.
- License 许可
- MIT
- 最近更新
- 2026-10-02
- Stars
- ★ 93
- Forks
- 8
01 前言 Front Matter
- name
- fill_pdf_form
- description
- Fills a PDF form with provided data. It maps field keys to their respective pages and applies values. It handles multi-line text areas by assigning specific strings to the identified sequential keys. For checkboxes, it uses the precise export values found during inspection. All dates must be formatted as 'xxxx-xx-xx'.
03 SKILL.md 正文
import pypdf
def fill_pdf_form(input_pdf_path: str, output_pdf_path: str, data: dict): """ Fills a PDF form. 'data' should be a flat dictionary where keys match the PDF field names. The function automatically identifies the page for each key and updates it. """ reader = pypdf.PdfReader(input_pdf_path) writer = pypdf.PdfWriter() writer.append_pages_from_reader(reader)
# Create a mapping of field keys to page indices
field_to_page = {}
for page_index, page in enumerate(reader.pages):
if "/Annots" in page:
for annot in page["/Annots"]:
obj = annot.get_object()
if "/T" in obj:
field_to_page[obj["/T"]] = page_index
# Group data by page index for update_page_form_field_values
page_updates = {}
for key, value in data.items():
if key in field_to_page:
p_idx = field_to_page[key]
if p_idx not in page_updates:
page_updates[p_idx] = {}
page_updates[p_idx][key] = value
# Apply updates page by page
for p_idx, fields in page_updates.items():
writer.update_page_form_field_values(writer.pages[p_idx], fields)
with open(output_pdf_path, "wb") as output_file:
writer.write(output_file)
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.