ocr-pdf

Recognizes and extracts text from PDF documents, automatically performing OCR on images within the document; used when extracting text from PDFs, performing OCR, or converting text-containing documents into editable text.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "ocr-pdf" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-fdb23b0fd55b47f996cd80c786e1012ee707a395723738eca5bc4c9687c4dabf. Verify the upstream source and version against https://skillhub.cn/skills/org-rn88lg3j/ocr-pdf before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Recognizes and extracts text from PDF documents, automatically performing OCR on images within the document; used when extracting text from PDFs, performing OCR, or converting text-containing documents into editable text.

0 Downloads

Introduction source: third_party · org-rn88lg3j · 1.0.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: "PDF文字提取"
description: "从PDF 文档中识别并提取文字内容,自动对其中图片进行OCR文字识别;当用户需要 PDF 提取文字、进行 OCR 识别、处理含文字的文档或转换为可编辑文本时使用。"

PDF文字提取

任务目标

  • 本 Skill 用于:从用户上传的 PDF 文档中识别并提取文字内容
  • 能力包含:PDF 文字提取、扫描页面自动检测、OCR 文字识别、格式保留、结构化输出、Markdown 文件生成
  • 触发条件:用户上传 PDF 并要求提取文字,或询问文档中的文字内容

前置准备

依赖说明

脚本所需的依赖包及版本:

pymupdf>=1.23.0
requests
pydantic-settings

安装命令:

pip install pymupdf>=1.23.0 requests pydantic-settings

支持的文件格式

  • PDF(支持文字版和扫描版)

操作步骤

标准流程

PDF 文字提取流程

  1. 接收 PDF 文件

    • 确认用户已上传 PDF 文件
    • 获取 PDF 文件的本地路径
  2. 调用脚本提取文字

    • 执行命令:python scripts/pdf_text_extractor.py <pdf_file_path>
    • 脚本会自动提取所有页面的文本,并检测扫描页面
    • 对于扫描页面,脚本会将其渲染为图片并保存到同级目录的 {pdf_name}_images 文件夹中
  3. 处理提取结果

    • 如果提取失败:告知用户错误信息,任务结束
    • 如果提取成功:进入步骤 4
  4. OCR 识别扫描页面(自动调用)

    • 检查返回结果中的 scanned_pages 列表
    • 如果存在扫描页面,对每个扫描页面执行以下操作:
      • 读取页面图片文件,转为 base64 编码
      • 调用 scripts.ocr_tools.ocr_for_data_base64(dataBase64=base64_string) 进行 OCR 识别
      • 将 OCR 识别结果替换原占位符,合并到最终文本中
    • 如果 scanned_pages 为空,跳过此步骤
  5. 生成输出结果

    • 合并所有页面的文字内容
    • 根据用户需求生成 Markdown 文件
    • 包含文件来源、提取状态、文字内容等信息
    • 使用清晰的标题和结构组织内容

可选分支

  • 当用户仅需查看文字内容:直接输出文字,不生成文件
  • 当用户要求保存结果:生成 .md 文件
  • 当 PDF 页面为扫描图片:自动进行 OCR 处理,无需用户额外操作
  • 当 OCR 识别失败:保留占位符并告知用户该页面识别失败

资源索引

  • 必要脚本:见 scripts/pdf_text_extractor.py

    • 用途:从 PDF 文件中提取文本内容,检测扫描页面并导出图片
    • 参数:PDF 文件路径
    • 输出:JSON 格式结果,包含提取的文本、扫描页面信息和元信息
  • OCR 工具:见 scripts/ocr_tools.py

    • 用途:对扫描页面图片进行 OCR 文字识别
    • 参数:图片 base64 编码或图片 URL
    • 输出:JSON 格式结果,包含识别的文字内容
  • API 配置:见 scripts/config.py

    • 用途:管理 OCR API 密钥
    • 注意:首次使用 OCR 功能时,如果未配置 API 密钥,需要使用 AskUserQuestion 询问用户

注意事项

PDF 文字提取

  • 格式保留:脚本会尽量保留原文的段落结构和标题层级
  • 扫描版 PDF:自动检测扫描页面并进行 OCR 识别
  • 复杂布局:表格、多栏等复杂布局的提取效果可能不佳
  • 加密 PDF:不支持加密或受密码保护的 PDF 文件

OCR 识别

  • 识别准确性:文字识别结果受图片清晰度、字体、背景等因素影响,可能存在误差
  • API 密钥:OCR 功能需要配置 API 密钥,首次使用时需要通过 AskUserQuestion 询问用户
  • 禁止在缺少 API 密钥时自行搜索或编造数据

通用注意事项

  • 隐私保护:处理的文件不会被存储,仅在当前会话中使用
  • 文件大小:建议处理小于 50MB 的文件,过大文件可能导致处理缓慢

使用示例

示例 1:PDF 文字提取

用户操作:上传 PDF 并要求"提取这个 PDF 的文字"

智能体处理:

  1. 确认 PDF 文件路径
  2. 执行脚本:python scripts/pdf_text_extractor.py ./document.pdf
  3. 获取提取结果,包含 10 页内容,其中第 3 页为扫描页面
  4. 读取第 3 页图片,转为 base64
  5. 调用 scripts.ocr_tools.ocr_for_data_base64(dataBase64=base64_string) 识别该页面
  6. 合并所有页面文字,生成 Markdown 文件:./extracted_from_pdf.md

示例 2:处理扫描版 PDF

用户操作:上传扫描版 PDF

智能体处理:

  1. 执行脚本提取文字
  2. 发现所有页面均为扫描页面,已导出为图片
  3. 对所有页面图片依次进行 OCR 识别
  4. 合并 OCR 结果,输出完整文字内容

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value92/100

Highlights

  • 高价值高频刚需场景:PDF文字提取+OCR识别解决用户核心文档处理痛点
  • 具备完整闭环体验:上传→提取→OCR→输出全流程
  • 支持文字版和扫描版PDF,自动检测并处理扫描页面
Trigger Precision95/100

Highlights

  • 触发词精准完整:覆盖PDF提取文字、OCR识别、文档处理等多种变体
  • 边界清晰:明确限定于PDF文档文字提取场景,不易与其他Skill重叠
  • description位置正确:顶层frontmatter完整,skill_body内部也有详细说明
Structure and Standards93/100

Highlights

  • Phase/步骤清晰:标准流程5步+可选分支,逻辑完整
  • 含端到端示例:2个完整使用示例覆盖典型场景
  • 资源索引完整:3个必要脚本均有详细说明和参数说明
Execution Reliability88/100

Areas to improve

  • API密钥配置说明不够详细 Reported severity: Minor

    仅提及通过AskUserQuestion询问用户,未说明具体配置方式和存储位置

    Recommendation: 建议在config.py说明中补充API密钥的具体配置格式和示例

Highlights

  • 工具来源明确:pymupdf等依赖包版本指定清晰
  • 异常处理完善:覆盖提取失败、OCR失败、加密PDF等场景
  • 隐私保护说明:明确文件仅在当前会话使用,不会被存储
Evidence Verifiability (mean of the first four)92/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.