Communitygithub.com

PDF 文本提取

从数字 PDF 中提取文本和简单的行式表格,供下游 AI 使用,无需 OCR 二进制文件。当用户要求读取 PDF、将 PDF 转为文本、从报表/报告中提取简单表格,或将 PDF 内容输入 LLM 管道时使用。

PDF 文本提取 是什么?

该技能从数字 PDF 文件中提取机器可读的文本和简单的行式表格,无需任何 OCR 二进制文件。它优先使用纯 Python PDF 库(如 pypdf 或 pdfminer.six),当无法提取文本时会清晰地报错。该工具包含一个基于行的简单表格检测器,用于下游清理,由 extract.py 模块实现:它返回一个包含文本(按页面分割)和表格(每行数据)的字典。该技能特别适用于将 PDF 内容输入 AI 总结、分类或结构化提取管道的场景——它支持 Claude Code、Coder、Cursor 和 Codex 等平台。对于需要精确合并单元格的扫描 PDF 或表格,应改用 OCR 工作流。关键模式包括:保留页面边界以便引用页码、对长文档按页/范围限制文本量、以及在未找到文本时抛出错误以免下游收到空提示。

兼容平台~Claude Code~Codex CLI~Cursor✓Gemini CLI
npx skills add https://github.com/baronguyen001/ai-automation-skills/tree/HEAD/skills/pdf-text-extract

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

PDF 文本提取 是做什么的?

当工作流需要对数字 PDF 进行总结、分类或结构化提取前获取机器可读文本时,请使用此技能。该辅助工具优先使用纯 Python PDF 库,并包含一个基于行的简单表格检测器,便于下游清理。

何时调用

  • 用户说:“从该 PDF 中提取文本”、“将 PDF 供给 AI”、“从该报告中提取表格”、“读取此对账单”。
  • 该 PDF 包含可选文本,无需 OCR。

何时不调用

  • PDF 是扫描图像;请改用 OCR 工作流。
  • 用户需要精确的像素级表格重建(含合并单元格与布局保真度)。

具体示例

用户输入:

从该 PDF 中提取文本和粗略表格,以便 Gemini 进行总结。

输出:

# 将 assets/extract.py 复制到项目中,然后:
from extract import extract_pdf

doc = extract_pdf("downloads/report.pdf")
print(doc["text"][:2000])
for table in doc["tables"]:
    print(table["page"], table["rows"][:3])

在目标项目中安装 pypdf 或 pdfminer.six。无需 OCR 二进制文件,当 PDF 无可用文本时,辅助工具会清晰报错。

要应用的模式

  1. 优先使用数字文本提取;除非源文件是扫描件,否则不要添加 OCR。
  2. 保留页面边界,以便下游提示可引用页码。
  3. 保持表格提取简单:按制表符或重复空格分割行,然后让后续的模式清洗步骤对列进行规范化。
  4. 当 PDF 较长时,按页/范围限制发送给 LLM 的文本量。
  5. 未找到文本时主动报错,而不是向下游发送空提示。

参考:assets/extract.py。

来源

提炼自作者自动化项目的生产实践。v1.0.0。 另见:[[gemini-structured-output]]、[[csv-report-writer]]、[[s3-uploader]]。

→ 使用 Trawlkit 构建完整的可运行机器人。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

baronguyen001/ai-automation-skills

Schedule any script to run on a recurring schedule on Windows (Task Scheduler) or Linux (cron) - register, list, and remove jobs from one command, with logging to a file and a guard against overlapping runs. Use for schedule a script, run nightly, set up a cron job, windows task scheduler, or run on a timer.

baronguyen001/ai-automation-skills

Turn a run's list of result dicts into a schema'd CSV and a Markdown table from one column spec - declare columns once, emit both, with stable ordering and safe escaping, stdlib only, no pandas. Use when the user asks to write results to CSV, export a report, make a markdown summary table, or save a run's output as a spreadsheet.

baronguyen001/ai-automation-skills

Strip HTML to clean plain text with the standard library only (no BeautifulSoup/lxml): drops script/style, turns block tags into line breaks, and collapses whitespace. Use when the user wants readable text from an HTML page/email, to clean scraped HTML before sending it to an LLM, or to build a text index from web content.

baronguyen001/ai-automation-skills

Persist records between scheduled runs as append-only JSON Lines (one object per line) with streaming reads and optional key-based dedup, stdlib only. Use when the user wants to log run results to JSONL, append events to a file, dedup records by id across runs, or keep a simple durable history without a database.

baronguyen001/ai-automation-skills

Rotate a pool of HTTP/SOCKS proxies with round-robin selection, failure tracking, and a cooldown that benches dead proxies before retrying. BYO proxy list via env - none are shipped. Use for rotate proxies, spread requests across proxies, avoid IP bans, retry through a different proxy, or proxy health check.

baronguyen001/ai-automation-skills

Parse an RSS 2.0 or Atom feed into normalized item dicts (title, link, id, published, summary) with the standard library only - no feedparser. Use when the user asks to read an RSS/Atom feed, poll a blog/news feed, extract feed entries, or watch a site that publishes a feed.

baronguyen001/ai-automation-skills

Upload and download run artifacts from S3-compatible storage with BYO bucket and credentials from env. Use when the user asks to store scraper output, archive reports, publish artifacts to object storage, fetch a prior run file, or use MinIO/R2/Spaces/S3 without hardcoding credentials.

baronguyen001/ai-automation-skills

Draft a short-form TikTok/Reels/Shorts or long-form video script from a topic and creator persona file - hook variants, beat-structured body, CTA, b-roll cues, caption overlays, and [STORY]/[NUMBER] slots so the model never fabricates personal facts. Use for write a video script, tiktok script, youtube script, or /shortform-script.

baronguyen001/ai-automation-skills

Give scheduled scripts memory between runs with one SQLite file - a seen-set for dedup, a key/value cursor to resume where you left off, and order-preserving new-item filtering. Use for dedup across runs, don't re-alert the same item, remember the last id, resume a scraper, or persist state between cron runs.

相关技能