Pdf processing

From seb1n/awesome-ai-agent-skills · View interactive version

Pdf processing is an AI agent skill from the GitHub repository seb1n/awesome-ai-agent-skills. Inspect, extract, OCR, create, merge, split, reorder, rotate, annotate, fill, redact, compress, secure, and verify PDF documents while preserving source files and visual fidelity. Use when working with one or more .pdf files; converting documents to or from PDF; extracting text, tables, images, meta

How to use this skill

Skill file

PDF Processing

Preserve the original, choose tools from what is actually available, and verify both document structure and rendered appearance.

Inputs

Collect or state:

Clarify ambiguous page references: human page labels may differ from zero- or one-based physical page numbers.

Output contract

Return:

  1. New output file(s) at explicit paths; never silently overwrite the source.
  2. Source and output SHA-256 hashes, byte sizes, page counts, and encryption status when determinable.
  3. A concise operation log: tools used, options, page mapping, OCR language, redactions, and metadata changes.
  4. Verification evidence for structure, content, and rendered appearance, plus limitations.
  5. Any password, signature, accessibility, font, OCR, or active-content caveats.

Do not claim exactness when the check was heuristic or a page could not be rendered.

Workflow

1. Preserve and inspect

python3 scripts/inspect_pdf.py /path/to/input.pdf --pretty
python3 scripts/inspect_pdf.py /path/to/input.pdf --output /path/to/report.json --pretty

This default scan reads bytes without invoking a PDF parser. With --output, it refuses input aliases and non-regular destinations, then atomically creates or replaces the report via a sibling temporary file. Use --deep only after the file is trusted enough to parse, or after the untrusted-input sandbox profile in step 2 is verified. Declare the decision explicitly:

python3 scripts/inspect_pdf.py /path/to/input.pdf --deep --trust-level trusted --pretty
python3 scripts/inspect_pdf.py /path/to/untrusted.pdf --deep --sandbox-profile-confirmed --pretty

Treat JavaScript, launch actions, automatic actions, embedded files, and rich media as inert hazards; do not activate them.

2. Select an available toolchain

Inventory installed tools and libraries before choosing a method. Read tool-routing.md for capability-based routing and fallback behavior. Prefer a tool that preserves the required features; a text extractor is not a page editor, and rasterization is not a faithful editable conversion.

For an untrusted PDF, parse or render only in a disposable, low-privilege sandbox with no secrets or network access; a read-only source mount; isolated temporary/output storage; CPU, memory, process, file-size, page, and time limits; and no host viewer, shell, URL-handler, or clipboard integration. Configure the parser/renderer to disable JavaScript, OpenAction/additional/launch actions, form submission, external URI fetching, attachment extraction/opening, rich media, and automatic font/resource downloads. Verify these controls for the exact tool/version. If the available parser or renderer cannot satisfy the profile, stop after raw-byte inspection and report the capability gap.

If no suitable dependency exists, explain the missing capability and propose an installation or alternate workflow. Do not install software or upload the PDF without permission.

3. Establish a visual and content baseline

Open or render a trusted original with a trusted local viewer before any layout-sensitive change. For an untrusted original, use only the verified sandbox profile from step 2; if it is unavailable, stop without parsing/rendering. Inspect representative pages and every page that will change. Record page count, dimensions/orientation, searchable text availability, form fields, annotations, bookmarks, attachments, encryption, and obvious font or image issues.

For scanned pages, determine whether OCR is needed. Preserve the original image layer unless the user explicitly requests destructive cleanup.

4. Apply the smallest transformation

Work on a temporary output, then move or copy it to the final requested path only after verification.

5. Verify structure and content

Follow verification-checklist.md. At minimum:

6. Render and inspect

Render every changed page and a representative sample of unchanged pages under the applicable trust/sandbox profile. Inspect at readable resolution for clipping, missing glyphs, shifted tables, broken images, blank pages, wrong rotation, and redaction leakage. For short or high-stakes documents, inspect every page. Open the final file in the user's intended viewer only when its trust classification and active-content controls permit it.

7. Deliver with evidence

Use processing-record-template.md for complex or regulated work. Report output paths, hashes, verification performed, failures, and untested behavior. Retain temporary artifacts only as long as needed and delete them only when authorized.

Safety and permission boundaries

Recovery

If processing fails, preserve the source and failed output separately, capture the exact command/tool/version and error, and retry from the unchanged original. If the output was distributed before a defect was found, identify affected versions and recipients but do not recall or replace files without authorization. For suspected redaction leakage or signature/key exposure, stop distribution and escalate immediately.

Examples

Extract a scanned contract

Request: “Extract this 38-page scanned contract into searchable text with page citations.”

Hash and render the original, OCR with the stated language, preserve the PDF image layer, spot-check names/numbers on every page, flag low-confidence passages, and deliver text with physical page references and an OCR limitation note.

Merge a board packet

Request: “Combine these five PDFs in agenda order and add bookmarks.”

Confirm order and page mapping, merge to a new file, preserve orientation and page sizes, add bookmarks, re-open with a second reader, render boundary pages, and report final page count and hash.

Redact customer identifiers

Request: “Remove account numbers before this PDF is shared publicly.”

Define the identifier pattern and all affected pages, apply true redaction to a copy, remove scoped metadata/comments/attachments, search and inspect with an independent parser, render every redacted page, and state that visual boxes alone were not used.

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.