返回 Skill 列表
extension
分类: 开发与工程无需 API Key

fill-pdf

使用结构化的上下文值通过pdftk填充交互式PDF表单。当用户提供了一个可填写的PDF文件加上字段数据(或自然语言上下文)并希望得到一个完成后的输出PDF、扁平化的最终副本,或者需要帮助将上下文键映射到PDF表单字段名称时使用。

person作者: jakexiaohubgithub

Fill PDF

Fill AcroForm PDFs by mapping context keys to form fields and running pdftk with an FDF payload.

Workflow

  1. Validate prerequisites.
  • Confirm pdftk is installed before doing form operations.
  • Treat this skill as AcroForm-focused; if the PDF has no fillable fields, report that and stop.
  1. Inspect field names.
  • Run:
pdftk <input.pdf> dump_data_fields_utf8
  • Capture exact FieldName values and use them as target keys.
  1. Build context map.
  • Normalize provided context into a flat JSON object where each key is an exact field name.
  • Convert values to strings when needed.
  • Leave missing fields out unless the user asks for explicit blanks.
  1. Fill the PDF with pdftk.
  • Preferred helper:
scripts/fill_pdf.sh --input <input.pdf> --context <context.json> --output <output.pdf> [--flatten]
  • The helper converts JSON context to FDF and calls:
pdftk <input.pdf> fill_form <tmp.fdf> output <output.pdf>
  1. Verify result.
  • Confirm output file exists and is non-empty.
  • If the user asks for non-editable output, use --flatten.

Quick Commands

List field names:

scripts/fill_pdf.sh --list-fields --input <input.pdf>

Fill from context JSON:

scripts/fill_pdf.sh --input <input.pdf> --context <context.json> --output <output.pdf>

Fill and flatten:

scripts/fill_pdf.sh --input <input.pdf> --context <context.json> --output <output.pdf> --flatten

Notes

  • Keep context keys aligned to exact PDF field names; guessing names causes silent misses.
  • Prefer dump_data_fields_utf8 output over visual assumptions from labels.
  • If a field does not populate, re-check case and punctuation in the key.

Resources

scripts/

  • fill_pdf.sh: Lists form fields and fills PDFs from a JSON context file via pdftk.