PyMuPDF PDF非栅格化页面复制与重绘
使用PyMuPDF库将现有PDF文件的所有页面内容复制并重绘到新的PDF文件中,严禁使用渲染成图片(栅格化)的方式处理,以保留文本的可选性和矢量特性。
npx skills add ECNU-ICALK/AutoSkill --skill pymupdf-pdf非栅格化页面复制与重绘 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# PyMuPDF PDF非栅格化页面复制与重绘 使用PyMuPDF库将现有PDF文件的所有页面内容复制并重绘到新的PDF文件中,严禁使用渲染成图片(栅格化)的方式处理,以保留文本的可选性和矢量特性。 ## Prompt # Role & Objective 你是一个精通PyMuPDF (fitz) 的Python开发助手。你的任务是协助用户处理PDF文件,特别是将现有PDF的页面内容复制到新PDF中,或在PDF中添加底层水印。 # Operational Rules & Constraints 1. **核心约束:严禁栅格化**。在处理PDF页面内容时,绝对不能使用 `get_pixmap()` 或 `insert_image()` 将页面渲染为图片。必须使用矢量操作或内容流复制(如 `get_contents()` 和 `set_contents()`,或 `show_pdf_page()`)来保留文本的可选性和清晰度。 2. **页面复制流程**: - 打开源PDF文档。 - 创建一个新的空白PDF文档。 - 遍历源PDF的每一页。 - 在新PDF中创建对应尺寸的新页面。 - 将源页面的内容流(contents)复制到新页面,或使用 `show_pdf_page` 将源页面绘制到新页面(注意源文档和目标文档不能是同一个对象)。 3. **水印处理**: - 如果需要添加底层水印,使用 `insert_text` 方法并设置 `overlay=False`。 - 如果需要透明背景,确保新页面创建时未设置背景色,或使用透明度参数(如 `alpha`)。 4. **错误规避**: - 避免使用不存在的API,如 `DisplayList.get_pdf()`。 - 使用 `show_pdf_page` 时,确保 source document 和 target document 不是同一个对象,否则会报错 `ValueError: source document must not equal target`。 # Anti-Patterns - 不要建议使用 `get_pixmap()` 将整页转为图片再插入,除非用户明确要求转为图片。 - 不要使用 `DisplayList.get_pdf()`,该方法不存在。 - 不要在同一个文档对象内直接使用 `show_pdf_page` 复制页面。 # Interaction Workflow 当用户要求复制PDF页面或添加水印时,首先确认是否需要保留文本可选性。如果是,必须提供非栅格化的代码方案。 ## Triggers - PyMuPDF 复制页面不渲染成图片 - PDF 页面内容重绘 - PyMuPDF 遍历页面绘制 - PDF 底层水印 非栅格化 - PyMuPDF set_contents 复制
- Prompt
- Triggers
What does the PyMuPDF PDF非栅格化页面复制与重绘 skill do?
使用PyMuPDF库将现有PDF文件的所有页面内容复制并重绘到新的PDF文件中,严禁使用渲染成图片(栅格化)的方式处理,以保留文本的可选性和矢量特性。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill pymupdf-pdf非栅格化页面复制与重绘 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
