Pdf

From zhixuli0406/DuDuClaw · View interactive version

Pdf is an AI agent skill from the GitHub repository zhixuli0406/DuDuClaw. Read and create PDF documents — extract text (and per-page text) from a PDF to JSON/markdown, and render markdown/plain text into a new PDF.

How to use this skill

Skill file

PDF 文件處理

處理 PDF 的兩件事:讀取抽取與建立。腳本用 uv run 執行,依賴以 PEP 723

inline metadata 宣告(讀取用 pypdf、建立用 reportlab);uv 不存在時改用

pip install pypdf==6.7.1 reportlab==4.4.10 後 python3 執行。

何時使用

腳本

腳本位於本技能的 scripts/ 目錄。兩種執行路徑,依你有沒有 Bash 工具擇一:

改用 office_script MCP 工具執行主程式內嵌、通過雜湊驗證的腳本(Linux/macOS):

例(把整理好的文字產成 PDF):

```json

{"skill": "pdf", "script": "create",

"args": ["report.md", "--out", "/你的agent目錄/attachments/report.pdf"]}

```

工具在私有目錄執行內嵌腳本,技能目錄中的腳本不會執行;個人/部門/公司層只能覆蓋提示文字。

旗標和值必須分開(拒絕 --out=...),輸出須為你的 agent 目錄內的新檔案,父目錄須已存在;

輸入拒絕符號連結與硬連結,輸出不覆寫既有檔案。成功後工具回傳實際輸出路徑;

產出檔案後務必依下方 📎DELIVER 協定交付。

1. 讀取抽取 — `extract.py`

uv run scripts/extract.py <input.pdf> --format json   # {"pages": ["p1 text", ...]}
uv run scripts/extract.py <input.pdf> --format md      # 逐頁文字,以 --- 分隔

2. 建立 — `create.py`

把 markdown 或純文字產成 PDF(#/## 標題會用較大字級,其餘為內文;CJK 以內建

字型排版):

來源型別依副檔名判定(.txt → 純文字,其餘 → markdown):

uv run scripts/create.py report.md --out /abs/out.pdf
uv run scripts/create.py notes.txt --out /abs/out.pdf

若需要把 Word/Excel/PPT 轉成 PDF,請改用對應的 docx / xlsx / pptx 技能的

to_pdf.py(LibreOffice headless)。

交付檔案給使用者(📎DELIVER 協定)

產出後在回覆最後另起一行:

📎DELIVER:/絕對路徑/report.pdf

路徑須為絕對路徑且位於你的 agent 工作目錄(或其 attachments/)下;標記行不顯示給

使用者,請另用文字說明。

API 模式同樣適用:用 office_script 產出 .pdf 後,一樣在最後一行輸出

📎DELIVER:<絕對路徑>——只回文字不算完成。

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.