---
name: pdf-exporter
description: >
  将 HTML 报告文件导出为支持中文的 PDF 文件。当用户要求"导出 PDF"、"下载 PDF"、
  "将报告保存为 PDF"、"生成 PDF 版本"时激活。
  MUST use this skill whenever exporting any report or data to PDF format.
  ❌ Do NOT use this skill for: reading PDFs, merging PDFs, OCR, or PDF form filling
     (use the `pdf` skill instead).
version: "1.0"
---

# PDF 导出技能（pdf-exporter）

## CRITICAL RULES

- MUST call `export_pdf.py` for ALL PDF export requests; NEVER write ad-hoc reportlab code
- MUST use the bundled `wqy-microhei.ttc` font; NEVER use Helvetica or other ASCII-only fonts for Chinese content
- NEVER fabricate a PDF file path; ALWAYS use the actual `output_path` returned by the script
- The script handles font registration automatically; no manual font setup needed

## 触发范围

**激活场景（MUST activate）：**
- 用户说"导出 PDF"、"下载 PDF"、"保存为 PDF"、"生成 PDF"
- 用户要求将某个 HTML 报告文件转换为 PDF
- 用户说"把报告发给我"且当前有 HTML 报告文件

**排除场景（Do NOT activate）：**
- 读取、解析、提取 PDF 内容 → 使用 `pdf` skill
- 合并、拆分、旋转 PDF → 使用 `pdf` skill
- PDF 表单填写 → 使用 `pdf` skill

---

## 执行流程

### Step 1 — 导出 PDF

FIRST, send the user this message:
> 【正在导出 PDF】正在将报告转换为 PDF 格式，支持中文显示，请稍候...

THEN run:
```bash
python3 /workspace/skills/pdf-exporter/scripts/export_pdf.py \
  --input  <html_file_path> \
  --output <output_pdf_path> \
  --title  "<报告标题>"
```

**参数说明：**

| 参数 | 说明 | 示例 |
|---|---|---|
| `--input` | 输入 HTML 文件的绝对路径 | `/workspace/skill/sql-report-generator/output/report_xxx.html` |
| `--output` | 输出 PDF 文件的绝对路径，建议与 HTML 同目录，扩展名改为 `.pdf` | `/workspace/skill/sql-report-generator/output/报告名称_xxx.pdf` |
| `--title` | PDF 标题（显示在文档首页），使用中文报告名称 | `"电力能耗趋势报告"` |

**Output（脚本输出 JSON）：**
```json
{
  "status": "success",
  "message": "PDF 导出成功",
  "output_path": "/workspace/skill/sql-report-generator/output/报告名称_xxx.pdf",
  "file_size_kb": 128.5,
  "chinese_font": true,
  "sections_count": 12
}
```

- `output_path`：生成的 PDF 文件路径，用于后续引用
- `chinese_font`：若为 `false` 说明字体文件缺失，需检查 `/workspace/skills/pdf-exporter/fonts/wqy-microhei.ttc`
- 若 `status` 为 `error`，读取 `message` 字段排查原因

---

## Final Reply Format

成功导出后，回复格式如下：

**Part 1 — 摘要**：一句话说明 PDF 已生成，包含文件大小。

**Part 2 — 文件地址标签**：
```
@@@@@<output_path 中 /workspace 之后的相对路径>@@@@@
```
例如：`@@@@@/skill/sql-report-generator/output/电力能耗趋势报告_1234567890.pdf@@@@@`

**Part 3 — 建议标签（最后一行，格式固定）**：
```
#####%下载 PDF%￥点击上方链接下载 PDF 文件￥ %查看原始报告%￥返回查看 HTML 版本报告￥#####
```

---

## Bundled Resources

```
skills/pdf-exporter/
├── SKILL.md                    # 本文件
├── scripts/
│   └── export_pdf.py           # PDF 导出脚本（支持中文、表格、标题层级）
└── fonts/
    └── wqy-microhei.ttc        # 文泉驿微米黑中文字体（5MB，支持简繁中文+日韩）
```

**依赖**：reportlab（已安装于 `/workspace/.local/lib/python3.11/site-packages`）

---

## Error Handling

| 错误信息 | 原因 | 处理方式 |
|---|---|---|
| `reportlab 未安装` | reportlab 未安装到 `/workspace/.local` | 参考安装文档重新安装 reportlab |
| `中文字体文件不存在` | `fonts/wqy-microhei.ttc` 缺失 | 检查字体文件是否在正确路径 |
| `读取 HTML 文件失败` | HTML 文件路径错误或不存在 | 确认 `--input` 路径正确 |
| `PDF 生成失败` | reportlab 内部错误 | 查看 stderr 输出获取详细错误 |

---

## Notes

- 字体文件路径固定为 `/workspace/skills/pdf-exporter/fonts/wqy-microhei.ttc`，脚本会自动查找，无需手动指定
- PDF 输出文件名建议使用中文报告名称 + 时间戳，如 `电力能耗趋势报告_1234567890.pdf`
- 脚本会自动从 HTML 中提取标题（h1~h4）、段落、表格，图表（Canvas/SVG）无法转换为 PDF 图形，将被忽略
- 如需保留图表，建议截图后嵌入 PDF（超出本 skill 范围）
