
Pdf Image Text Extractor
- 238 installs
- 316 repo stars
- Updated August 4, 2026
- redfox-data/redfox-community
Use pdf-image-text-extractor for development tasks
About
pdf-image-text-extractor: A skill for development. This provides functionality for development workflows.
- pdf-image-text-extractor
Pdf Image Text Extractor by the numbers
- 238 all-time installs (skills.sh)
- +19 installs in the week ending Aug 4, 2026 (Skillselion tracking)
- Ranked #1,585 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/redfox-data/redfox-community --skill pdf-image-text-extractorAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 238 |
|---|---|
| repo stars | ★ 316 |
| Last updated | August 4, 2026 |
| Repository | redfox-data/redfox-community ↗ |
What it does
Use pdf-image-text-extractor for development tasks
Files
PDF和图片文字提取
---
1. 简介
PDF和图片文字提取是一款从图片和 PDF 文档中智能识别并提取文字内容的工具。无论是手机拍摄的图片、扫描版 PDF 还是电子版 PDF,都能自动检测文字存在性、提取全部文字并保留原始排版格式,最终输出结构化的 Markdown 文本。
核心价值:告别手动抄录,一键提取文档中的文字,节省 90% 的转录时间。
适用对象:学生(提取教材/论文文字)、办公人员(提取合同/发票信息)、内容创作者(提取参考资料)、开发者(批量处理文档)。
---
2. 功能特性
| 功能 | 说明 |
|---|---|
| 📷 图片文字识别 | 支持 PNG、JPG、JPEG、GIF、WebP、BMP 等常见格式,自动检测并提取图片中的文字 |
| 📄 PDF 文字提取 | 同时支持扫描版和文字版 PDF,保留段落结构和标题层级 |
| 🎯 智能判断 | 自动判断文档是否包含文字,无文字时明确提示,避免空等 |
| 📝 结构化输出 | 输出 Markdown 格式,标题、正文、段落层次分明,可直接阅读或二次编辑 |
| 🌐 多语言支持 | 支持中文、英文等多种语言文字的识别和提取 |
| 🔒 隐私保护 | 处理的文件仅在当前会话中使用,不会被持久化存储 |
特色亮点:
- 图片文字提取无需安装任何额外依赖,直接使用内置
read_image工具 - PDF 文字提取采用 PyMuPDF 引擎,精准识别字体大小和粗体格式,自动生成 Markdown 标题层级
- 输出结果可灵活选择:直接展示、保存为
.md文件、或嵌入其他文档
---
3. 一键安装
依赖安装
| 依赖 | 说明 | 安装命令 |
|---|---|---|
pymupdf>=1.23.0 | PDF 文字提取核心引擎 | pip install pymupdf>=1.23.0 |
注意:图片文字提取功能直接使用 AI 内置的read_image工具,无需安装任何额外依赖。pymupdf仅在需要提取 PDF 文字时才需安装。
环境要求
- Python 3.7+
- 支持的操作系统:macOS / Linux / Windows
---
4. 使用指南
图片文字提取
操作流程:
1. 上传图片 — 将包含文字的图片文件上传到对话中 2. 自动识别 — 智能体使用 read_image 工具自动识别图片内容,提取所有文字(包括标题、正文、注释、水印等) 3. 判断文字存在性 — 如果检测到文字,进入下一步;如果未检测到文字,智能体会明确告知"图片中未包含可提取的文字" 4. 格式化输出 — 保持原有的文字结构和排版,整理为易读的格式
可选分支:
- 当用户仅需查看文字内容:直接输出文字,不生成文件
- 当用户要求保存结果:生成
.md文件 - 当图片文字模糊或难以识别:说明情况并提供最佳识别结果
PDF 文字提取
操作流程:
1. 上传 PDF 文件 — 将 PDF 文件上传到对话中 2. 执行提取脚本:
python scripts/pdf_text_extractor.py <pdf_file_path>3. 查看提取结果 — 脚本返回 JSON 格式结果,包含:
success: 是否成功text: Markdown 格式的文本内容page_count: 总页数error: 错误信息(如有)
4. 格式化输出 — 脚本返回的文本为 Markdown 格式,可直接展示或保存为文件
脚本参数说明:
| 参数 | 说明 | 必填 |
|---|---|---|
<pdf_file_path> | PDF 文件的本地路径 | 是 |
输出格式示例:
{
"success": true,
"text": "## 第一章 引言\n\n这是正文内容...\n\n---\n\n## 第二章 方法\n\n...",
"page_count": 10,
"error": ""
}可选分支:
- 当 PDF 包含扫描图片:提示用户该页面为扫描图片,可能需要 OCR 处理
- 当提取失败:检查文件是否存在、格式是否正确、PDF 是否加密
常用命令 / 指令速查表
| 场景 | 命令 / 操作 |
|---|---|
| 提取图片文字 | 上传图片,直接让智能体识别 |
| 提取 PDF 文字 | python scripts/pdf_text_extractor.py <路径> |
| 仅查看不保存 | 提取后直接输出文本即可 |
| 保存为文件 | 提取后要求智能体生成 .md 文件 |
| 安装依赖 | pip install pymupdf>=1.23.0 |
---
5. 使用场景
| 场景 | 角色 | 需求 | 使用方式 | 预期收益 |
|---|---|---|---|---|
| 🔬 学术研究 | 研究生 / 学者 | 从扫描版 PDF 论文中提取文字做笔记和引用 | 上传 PDF → 执行提取脚本 → 获取 Markdown 原文 | 无需手动打字,准确率 95%+,直接复制到论文中引用 |
| 💼 办公文档处理 | 行政 / 法务 / 财务 | 从图片合同、发票、扫描件中提取关键文字信息 | 上传图片 → 智能体识别 → 提取文字 | 告别逐字手打,提升文档数字化效率 |
| ✍️ 内容二次创作 | 自媒体 / 编辑 | 从 PDF 电子书中提取文字作为创作素材 | 上传 PDF → 提取全部文字 → 保存为 .md 编辑 | 快速获取原文,聚焦内容创作而非转录 |
| 💻 批量文档处理 | 开发者 / 数据分析师 | 批量处理多个 PDF 文档,提取结构化数据 | 编写脚本循环调用 pdf_text_extractor.py | 自动化处理,可集成到数据处理流水线中 |
---
6. 项目架构
目录结构
pdf-image-text-extractor/
├── SKILL.md # Skill 定义文件
├── README.md # 用户文档(中文)
├── README.en.md # 用户文档(英文)
└── scripts/
└── pdf_text_extractor.py # PDF 文字提取核心脚本技术栈
| 技术 | 用途 | 版本要求 |
|---|---|---|
| Python | 脚本运行环境 | 3.7+ |
| PyMuPDF (fitz) | PDF 解析和文字提取引擎 | >=1.23.0 |
| urllib | 内置标准库,用于 HTTP 请求 | Python 内置 |
核心模块说明
`scripts/pdf_text_extractor.py` — PDF 文字提取核心脚本:
- `extract_text_from_pdf(pdf_path)` — 主提取函数,打开 PDF 文件,逐页解析文本块,根据字体大小(>16px 判定为标题)和粗体属性自动生成 Markdown 格式(## 和 ### 标题),输出含页面分隔符的结构化文本
- `record_skill_usage()` — 调用 Redfox 记录接口,记录工具使用次数(不影响主流程)
- `main()` — CLI 入口,接收 PDF 文件路径参数,调用提取函数并输出 JSON 结果
资源索引
| 资源 | 路径 | 说明 |
|---|---|---|
| 核心脚本 | scripts/pdf_text_extractor.py | PDF 文字提取脚本 |
| 用户文档 | README.md | 中文使用说明 |
| 用户文档 | README.en.md | 英文使用说明 |
---
7. 常见问答
安装
Q:安装 pymupdf 时报错怎么办? A:确保 Python 版本 >= 3.7。部分系统可能需要先安装系统级依赖:macOS 可尝试 brew install mupdf,Linux 可尝试 apt-get install libmupdf-dev。
Q:是否必须安装 pymupdf? A:如果只使用图片文字提取功能,无需安装。仅在需要提取 PDF 文字时才需要安装 pymupdf。
使用
Q:图片文字提取的准确率如何? A:文字识别结果受图片清晰度、字体、背景等因素影响。清晰图片准确率可达 95%+,模糊或复杂背景的图片准确率会下降。
Q:PDF 提取后文字格式是什么样的? A:脚本自动生成 Markdown 格式输出,大字体行自动转为 ## 标题,粗体大字体为 ### 标题,不同页面之间用 --- 分隔。
Q:能否处理加密的 PDF? A:不支持加密或受密码保护的 PDF 文件。需要先解密后再提取。
Q:提取的文字可以保存吗? A:可以。提取后要求智能体生成 .md 文件即可保存到本地。
故障排除
Q:PDF 提取结果为空怎么办? A:可能原因:1) PDF 是扫描图片(图片型 PDF),需要使用 OCR 工具;2) PDF 本身不含文字层。对于扫描版 PDF,建议先使用 OCR 工具预处理。
Q:文件过大导致处理缓慢? A:建议处理小于 50MB 的文件。过大的文件可在提取前进行分割处理。
Q:提示"文件不存在"? A:确认 PDF 文件路径正确,文件已上传到工作目录中。可使用绝对路径避免路径问题。
Q:图片中未检测到文字? A:可能原因:1) 图片确实不含文字;2) 图片中的文字过于模糊或与背景融合。尝试使用更高清晰度的图片重新提取。
PDF & Image Text Extractor / pdf-image-text-extractor
---
Introduction
Recognize and extract text from images or PDF documents. Supports multiple image formats and PDF files, automatically detects text presence, preserves original formatting, and outputs structured results.
Core Value
- Dual Format Coverage: Supports both images (PNG, JPG, GIF, WebP, etc.) and PDF documents — one tool for both scenarios.
- Format Preservation: Maintains original paragraph structure, heading hierarchy, and layout order during extraction, minimizing rework.
- Flexible Output: View extracted results directly or save as a Markdown file — choose what works for you.
Who It's For
- 📄 Office Workers — Quickly extract editable text from scans and screenshots, eliminating manual transcription.
- 🎓 Students / Researchers — Extract text from PDF papers and course materials for easy citation and organization.
- 💼 Content Creators — Pull text from image assets and convert to editable copy for further editing.
---
Features
Core Features
- Image Text Recognition: Upload an image and automatically detect and extract all text content — titles, body text, annotations, watermarks — while preserving the original layout.
- PDF Text Extraction: Extract text from all pages of text-based PDFs, retaining paragraph structure and heading hierarchy, output in Markdown format.
- Text Presence Detection: Automatically determines whether an image or page contains extractable text and promptly informs you when none is found.
- Multi-language Support: Recognizes text in Chinese, English, and other languages.
- Scanned PDF Detection: When a PDF page is a scanned image, alerts you that direct extraction is unavailable and suggests OCR processing.
- Result Saving: Extracted results can be saved as a
.mdfile on demand, including source, extraction status, and text content.
---
Usage Guide
Simply describe your need in natural language and upload an image or PDF — no commands to memorize.
Quick Reference
| Intent | Example Phrase | Result |
|---|---|---|
| Extract image text | "Extract the text from this image" | Recognizes all text in the image, preserving original layout |
| Extract PDF text | "Extract the text from this PDF" | Extracts text page by page, retaining paragraphs and heading levels |
| Extract and save | "Extract the text from this PDF and save it" | Extracts text and generates a .md file |
| Handle scanned PDF | "Read the text from this scanned document" | Detects scanned pages and alerts you; extracts from text-based pages |
---
Use Cases
| Scenario | Role | Example Phrase | Benefit |
|---|---|---|---|
| Image text to editable copy | Office Worker | "There's text in this screenshot, extract it" | Skip manual typing, get editable text quickly |
| PDF paper excerpt | Student / Researcher | "Extract the text from this PDF paper" | Preserve original structure for easy citation and organization |
| Scanned document content | Admin / Finance | "Can you read the text from this scan?" | Auto-detect scanned pages; extract from text-based pages normally |
| Asset text re-purposing | Content Creator | "Convert the copy in this image to text" | Quickly get text assets for re-editing and publishing |
PDF和图片文字提取 / pdf-image-text-extractor
---
简介
从图片或 PDF 文档中识别并提取文字内容,支持多种图片格式和 PDF 文件,自动判断是否包含文字并保留原始格式输出结构化结果。
核心价值
- 双格式覆盖:同时支持图片(PNG、JPG、GIF、WebP 等)和 PDF 文档,一个工具搞定两类场景。
- 格式保留:提取时尽量保持原文的段落结构、标题层级和排版顺序,减少二次整理。
- 灵活输出:可直接查看提取结果,也可保存为 Markdown 文件,按需选择。
适用对象
- 📄 办公人士 — 快速从扫描件、截图中提取可编辑文字,免去手动录入。
- 🎓 学生 / 研究者 — 从 PDF 论文、课件中提取文字内容,便于引用与整理。
- 💼 内容创作者 — 从图片素材中获取文字素材,转为可编辑文本再加工。
---
功能特性
核心功能
- 图片文字识别:上传图片后自动检测并提取其中的标题、正文、注释、水印等所有文字内容,保持原有排版。
- PDF 文字提取:从文字版 PDF 中提取全部页面文本,保留段落结构与标题层级,输出为 Markdown 格式。
- 文字存在性判断:自动判断图片或页面中是否包含可提取文字,无文字时及时告知。
- 多语言支持:支持识别中文、英文等多种语言文字。
- 扫描版 PDF 检测:当 PDF 页面为扫描图片时,提示用户该页面无法直接提取,建议使用 OCR 处理。
- 结果保存:提取结果可按需保存为
.md文件,包含文件来源、提取状态与文字内容。
---
使用指南
直接用自然语言描述需求,上传图片或 PDF 即可,无需记忆命令。
常用说法速查
| 意图 | 示例话术 | 效果 |
|---|---|---|
| 提取图片文字 | 「帮我把这张图片里的文字提取出来」 | 识别图片中的所有文字,保持原有排版输出 |
| 提取 PDF 文字 | 「提取这个 PDF 的文字」 | 逐页提取 PDF 文本,保留段落与标题结构 |
| 提取并保存 | 「把这份 PDF 的文字提取出来保存」 | 提取文字并生成 .md 文件 |
| 处理扫描版 PDF | 「这份扫描件里的文字帮我读出来」 | 检测扫描页面并提示,对可提取部分正常输出 |
---
使用场景
| 场景 | 角色 | 示例问法 | 收益 |
|---|---|---|---|
| 图片文字转可编辑 | 办公人士 | 「截图里有段话,帮我提取出来」 | 免去手动录入,快速获得可编辑文字 |
| PDF 论文摘录 | 学生 / 研究者 | 「把这篇 PDF 的文字提取出来」 | 保留原文结构,方便引用与整理 |
| 扫描件内容获取 | 行政 / 财务 | 「这份扫描件能读出文字吗」 | 自动检测扫描页面,对可提取部分正常输出 |
| 素材文字再加工 | 内容创作者 | 「图片里的文案帮我转成文字」 | 快速获取文字素材,便于二次编辑与发布 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
PDF 文字提取脚本
功能:从 PDF 文件中提取文本内容并保留格式,输出为 Markdown 格式
"""
import sys
import json
from pathlib import Path
import urllib.request
import urllib.error
try:
import fitz # PyMuPDF
except ImportError:
print(json.dumps({
'success': False,
'error': '缺少依赖:pymupdf。请安装:pip install pymupdf',
'text': '',
'page_count': 0
}, ensure_ascii=False))
sys.exit(1)
def extract_text_from_pdf(pdf_path: str) -> dict:
"""
从 PDF 文件中提取文本内容并保留格式
参数:
pdf_path: PDF 文件路径
返回:
dict: {
'success': bool,
'text': str, # Markdown 格式的文本
'page_count': int,
'error': str (如果失败)
}
"""
try:
# 验证文件存在
pdf_file = Path(pdf_path)
if not pdf_file.exists():
return {
'success': False,
'error': f'文件不存在:{pdf_path}',
'text': '',
'page_count': 0
}
# 验证文件格式
if not pdf_file.suffix.lower() == '.pdf':
return {
'success': False,
'error': f'文件格式错误:{pdf_file.suffix},仅支持 PDF 格式',
'text': '',
'page_count': 0
}
# 打开 PDF 文件
doc = fitz.open(pdf_path)
page_count = len(doc)
if page_count == 0:
return {
'success': False,
'error': 'PDF 文件为空,无任何页面',
'text': '',
'page_count': 0
}
# 提取所有页面的文本
markdown_content = []
for page_num in range(page_count):
page = doc[page_num]
# 添加页面分隔符
if page_num > 0:
markdown_content.append('\n---\n')
# 提取文本块
blocks = page.get_text("dict")["blocks"]
page_text = []
for block in blocks:
if block["type"] == 0: # 文本块
block_text = []
for line in block["lines"]:
line_text = ""
for span in line["spans"]:
text = span["text"].strip()
if text:
# 检测是否为标题(通过字体大小判断)
font_size = span["size"]
is_bold = "bold" in span["font"].lower()
if font_size > 16: # 大字体可能是标题
if line_text:
block_text.append(line_text)
line_text = f"## {text}" if not is_bold else f"### {text}"
else:
line_text += text + " "
if line_text.strip():
block_text.append(line_text.strip())
if block_text:
page_text.append('\n'.join(block_text))
markdown_content.append('\n\n'.join(page_text))
doc.close()
# 合并所有内容
full_text = '\n'.join(markdown_content)
# 清理多余的空行
while '\n\n\n' in full_text:
full_text = full_text.replace('\n\n\n', '\n\n')
return {
'success': True,
'text': full_text.strip(),
'page_count': page_count,
'error': ''
}
except Exception as e:
return {
'success': False,
'error': f'处理 PDF 时发生错误:{str(e)}',
'text': '',
'page_count': 0
}
def record_skill_usage():
"""
记录工具调用,每次使用时调用一次记录接口
接口地址:https://redfox.hk/story/api/skill/record/save
固定参数:source = pdf提取图片
"""
try:
url = 'https://redfox.hk/story/api/skill/record/save'
data = json.dumps({'source': 'pdf提取图片'}, ensure_ascii=False).encode('utf-8')
req = urllib.request.Request(
url,
data=data,
headers={'Content-Type': 'application/json'},
method='POST'
)
with urllib.request.urlopen(req, timeout=5) as resp:
resp.read()
except Exception:
# 记录接口调用失败不影响主流程,静默忽略
pass
def main():
"""主函数"""
if len(sys.argv) < 2:
print(json.dumps({
'success': False,
'error': '请提供 PDF 文件路径作为参数',
'text': '',
'page_count': 0
}, ensure_ascii=False))
sys.exit(1)
pdf_path = sys.argv[1]
result = extract_text_from_pdf(pdf_path)
# 记录接口调用
record_skill_usage()
# 输出 JSON 格式结果
print(json.dumps(result, ensure_ascii=False, indent=2))
# 如果失败,退出码为 1
if not result['success']:
sys.exit(1)
if __name__ == '__main__':
main()