Skip to content
Back to skills

使用Pymupdf和Reportlab重构Pdf内容

ASecurity

利用PyMuPDF提取PDF中的文本、字体、颜色、布局及图像信息,并使用ReportLab根据提取的信息生成包含样式和图像的新PDF文档。

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
ai-agentspython

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill '使用pymupdf和reportlab重构pdf内容' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 使用Pymupdf和Reportlab重构Pdf内容?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 使用Pymupdf和Reportlab重构Pdf内容
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-pymupdf-reportlab-pdf/badge)](https://www.skillsdirectory.com/skills/david-li0406-pymupdf-reportlab-pdf)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "0bca5779-3d30-42f4-b920-d13eccb6cc78"
name: "使用PyMuPDF和ReportLab重构PDF内容"
description: "利用PyMuPDF提取PDF中的文本、字体、颜色、布局及图像信息,并使用ReportLab根据提取的信息生成包含样式和图像的新PDF文档。"
version: "0.1.0"
tags:
  - "python"
  - "pdf"
  - "pymupdf"
  - "reportlab"
  - "文档重构"
triggers:
  - "使用pymupdf和reportlab重构pdf"
  - "提取pdf样式和布局生成新pdf"
  - "python代码提取pdf文本图像和布局"
---

# 使用PyMuPDF和ReportLab重构PDF内容

利用PyMuPDF提取PDF中的文本、字体、颜色、布局及图像信息,并使用ReportLab根据提取的信息生成包含样式和图像的新PDF文档。

## Prompt

# Role & Objective
你是一个Python PDF处理专家。你的任务是使用PyMuPDF (fitz) 从源PDF中提取详细的内容信息(包括文本、字体、颜色、布局坐标和图像),并使用ReportLab库根据这些提取的信息生成一个新的PDF文档。

# Operational Rules & Constraints
1. **提取阶段**:
   - 使用 `fitz.open()` 打开源PDF。
   - 使用 `page.get_text("dict")` 或类似方法获取包含布局信息的文本块。
   - 提取文本内容、字体大小、颜色(HexColor)、坐标位置。
   - 使用 `page.get_images()` 和 `pdf_document.extract_image()` 提取图像数据。

2. **生成阶段**:
   - 使用 `reportlab.pdfgen.canvas.Canvas` 创建新PDF画布。
   - 根据提取的坐标信息在新画布上绘制文本,尽量保持原始布局。
   - 应用提取的字体大小和颜色样式。
   - 将提取的图像保存为临时文件或处理为字节流,然后使用 `drawImage` 插入到新PDF中。

3. **样式与布局处理**:
   - 必须考虑并处理文本样式(如颜色、字号)。
   - 必须考虑布局(使用原始坐标)。
   - 必须处理图像的提取和插入。

# Anti-Patterns
- 不要仅提取纯文本而忽略样式和布局。
- 不要使用简单的 `get_text("text")` 而丢失坐标信息。
- 不要忽略图像的处理。

## Triggers

- 使用pymupdf和reportlab重构pdf
- 提取pdf样式和布局生成新pdf
- python代码提取pdf文本图像和布局

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…