用途
PDF Reader 是一个 PDF 读取技能,用于从 PDF 文件中读取并提取内容,转换成结构化文字。它支持本地文件和网络 URL,适合需要阅读论文、查看 PDF 文件内容、或从 PDF 中提取文字资料的场景。
触发条件
当用户出现以下情况时加载此技能:
- 用户说「讀取 PDF」「read PDF」「打開論文」「看這篇」
- "open paper"、"extract from PDF"
- 用户提供 PDF 文件路径或 URL
- 用户提供 PMID 需要获取全文
主要能力
该技能通过以下工具完成读取:
MCP Tools (microsoft-mar)
| Tool | 用途 | 参数 |
|---|---|---|
| convert_to_markdown | 将 PDF 转换为 Markdown | uri (file:// 或 http://) |
MCP Tools (pubmed-search)
| Tool | 用途 | 参数 |
|---|---|---|
| get_article_fulltext_links | 取得全文链接 | pmid |
Python Scripts (可选)
技能提供了可选的 Python 脚本 scripts/pdf_utils.py,基于 PyMuPDF (fitz),包含三个函数:
# scripts/pdf_utils.py
import fitz # PyMuPDF
def extract_text(pdf_path: str) -> str:
"""提取 PDF 文字"""
doc = fitz.open(pdf_path)
text = ""
for page in doc:
text += page.get_text()
return text
def extract_images(pdf_path: str, output_dir: str) -> list:
"""提取 PDF 圖片"""
# ...實作
pass
def extract_references(pdf_path: str) -> list:
"""提取參考文獻"""
# ...實作
pass
其中 extract_images 和 extract_references 的具体实现未在资料中给出,仅保留函数声明。
使用方式
1. 本地 PDF 读取
用户提供本地路径(如 C:\papers\article.pdf):
convert_to_markdown(uri="file:///C:/papers/article.pdf")
返回 Markdown 格式文字。
2. 网络 PDF 读取
用户提供 URL 或 PMID:
- 如果是 PMID,先调用
get_article_fulltext_links(pmid)取得 PDF URL - 再调用
convert_to_markdown(uri="https://...") - 返回 Markdown 格式文字
3. 批量处理模式
# 處理多個 PDF
pdf_files = [
"C:/papers/paper1.pdf",
"C:/papers/paper2.pdf",
"C:/papers/paper3.pdf"
]
for pdf in pdf_files:
content = convert_to_markdown(uri=f"file:///{pdf}")
save_to_notes(content, pdf)
# Checkpoint: 記錄處理進度
update_checkpoint(processed=pdf)
批量处理时通过 Checkpoint 记录处理进度。
输出格式
输出为 Markdown 结构,包含文件信息(文件名、页数、处理时间)、提取内容(按论文结构分段:Abstract、Introduction、Methods、Results、Discussion、References)以及图表清单(图表、页码、说明)。示例:
## PDF 讀取結果
**檔案**: article.pdf
**頁數**: 12
**處理時間**: 3.2s
---
### 提取內容
# [論文標題]
## Abstract
[摘要內容...]
## Introduction
[介紹內容...]
## Methods
[方法內容...]
## Results
[結果內容...]
## Discussion
[討論內容...]
## References
1. Author et al. (2024). Title...
2. ...
---
### 圖表清單
| 圖表 | 頁碼 | 說明 |
|------|------|------|
| Figure 1 | p.3 | Study flowchart |
| Table 1 | p.5 | Baseline characteristics |
使用范例
范例 1:本地 PDF
用户:「讀取 C:\papers\remimazolam-study.pdf」
执行:convert_to_markdown(uri="file:///C:/papers/remimazolam-study.pdf")
范例 2:从 PMID 取得 PDF
用户:「讀取 PMID 38353755 的全文」 执行:
get_article_fulltext_links(pmid="38353755")convert_to_markdown(uri=pmc_url)
范例 3:批量读取
用户:「讀取 papers/ 資料夾中的所有 PDF」 执行:
- 列出文件夹中的 PDF 文件
- 循环处理每个文件
- 建立 Checkpoint 追踪进度
错误处理
| 错误 | 处理方式 |
|---|---|
| PDF 加密 | 提示用户提供密码或使用其他版本 |
| 图片 PDF(扫描) | 提示需要 OCR,建议使用其他工具 |
| 网络错误 | 重试 3 次,失败后提示用户下载 |
相关技能
- note-writer - 撰写笔记
- report-writing - 组合技能:读取 + 撰写
限制
- 加密 PDF 无法直接读取,需用户提供密码或改用其他版本
- 扫描版(图片型)PDF 需要 OCR,本技能不直接处理,建议使用其他工具
- 网络读取失败时会重试 3 次,仍失败则提示用户下载
- extract_images 与 extract_references 的具体实现暂未提供