Pdf

From ahang1598/doubao-workbuddy-qwenwork-skills · View interactive version

Pdf is an AI agent skill from the GitHub repository ahang1598/doubao-workbuddy-qwenwork-skills. Read, create, inspect, render, and verify PDF files where visual layout matters, including fillable AcroForms. Use Poppler rendering plus Python tools such as reportlab, pdfplumber, and pypdf for generation and extraction.

How to use this skill

Skill file

PDF Skill

When To Use

Tools + Contract Requirements

Immediately before the first create/edit authoring command, run mark_artifact_operation_started.mjs successfully exactly once using the command below. Do not run it for read-only work. For edits, replace create with edit; adjust the expected count and output format to match the requested outputs.

node container_tools/mark_artifact_operation_started.mjs --operation-kind create --expected-output-count 1 --output-format pdf

Workflow

  1. Prefer visual review: render PDF pages to PNGs and inspect them.
  1. Use reportlab to generate PDFs when creating new documents.
  2. Use pdfplumber or pypdf for text extraction and quick checks; do not rely on text extraction for layout fidelity.
  3. After each meaningful update, re-render pages and verify alignment, spacing, and legibility.

Fill And Validate AcroForms

Visual review alone is not a correctness check for a fillable PDF. A page /Widget annotation can render a value from its appearance stream while the canonical /AcroForm/Fields tree is missing or contains a stale value.

  1. Keep the result interactive by default; set flatten=True only when the user explicitly requests a completed, static form. Preserve the source PDF, and do not flatten a signed PDF without an explicit workflow decision.
  2. Inspect both representations before filling: enumerate fields from reader.get_fields() and /Widget annotations from every page's /Annots, following /Parent and /Kids. If a widget and a canonical field have the same name but are distinct objects with no /Parent relationship, do not call reattach_fields() blindly: it can create a second top-level field with the same name. Report the ambiguity or produce a static result.
  3. Recover genuinely orphaned widgets, fill all pages, and write the result with pypdf:
from pypdf import PdfReader, PdfWriter
from pypdf.generic import NameObject

reader = PdfReader(input_pdf)
writer = PdfWriter()
writer.clone_document_from_reader(reader)

# Restores widgets that are missing from /AcroForm/Fields.
writer.reattach_fields()
fields = writer.get_fields() or {}
missing = set(expected_values) - set(fields)
if missing:
    raise ValueError(f"Form fields not found after repair: {sorted(missing)}")

values_to_write = dict(expected_values)
if flatten:
    # Paint every existing value before removing every widget.
    values_to_write = {
        name: field.get("/V", "/Off" if field.get("/FT") == "/Btn" else "")
        for name, field in fields.items()
    }
    values_to_write.update(expected_values)

writer.update_page_form_field_values(
    None, values_to_write, auto_regenerate=False, flatten=flatten
)

if flatten:
    # pypdf's flatten=True paints appearances but does not remove widgets.
    writer.remove_annotations(subtypes="/Widget")
    writer.root_object.pop(NameObject("/AcroForm"), None)

with open(output_pdf, "wb") as stream:
    writer.write(stream)
  1. Reopen the written PDF before delivery. For an interactive result, require every expected field to be present in get_fields() with the expected /V, enumerate page widgets again, and confirm their effective /V (the widget value or inherited /Parent value) agrees. Confirm each updated widget has a non-empty /AP /N appearance and render the final pages to catch stale or clipped appearances. Do not rely on /NeedAppearances or a successful PNG render as proof that logical field data was updated.
  2. For a flattened result, require zero /Widget annotations and no remaining /AcroForm field tree after reopening, then render the final pages. Keep an editable copy when the user may need to revise the form.

Temp And Output Conventions

Dependencies

Prefer the Codex bundled workspace/runtime dependencies when available. The primary runtime is expected to include:

If a dependency is missing, install only what is needed.

Python packages:

uv pip install reportlab pdfplumber pypdf

If uv is unavailable:

python3 -m pip install reportlab pdfplumber pypdf

System tools for rendering:

# macOS (Homebrew)
brew install poppler

# Ubuntu/Debian
sudo apt-get install -y poppler-utils

If installation is not possible in this environment, tell the user which dependency is missing and how to install it locally.

Environment

No required environment variables.

Rendering Command

pdftoppm -png "$INPUT_PDF" "$OUTPUT_PREFIX"

Quality Expectations

Final Checks

Final response

Final Response Citations

For file citations, set path to the verified absolute file path on the task host. Omit mode.

Some illustrative examples, real responses use verified targets outside code fences.

:codex-file-citation{path="/absolute/path/review.pdf" purpose="output"}
The review of :codex-file-citation{path="/absolute/path/review.pdf" purpose="source"} is due Friday.

Additional Citation Guidance

For PDF Q&A, inspect complete relevant pages and preserve material headings, table/figure labels, footnotes, sources, and sample sizes. PDF citations support only plain file citations; do not add artifact_kind, page_number, or other locators.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.