pdf-extract-create-workflow
它能做什么
这项技能涵盖完整的 PDF 流程:获取 PDF、读取其文字,并用 reportlab 生成新的格式化 PDF。适合处理来自网站或自己电脑的 PDF、并需要生成新文档的人。
适用场景
- ✓当 PDF 位于网站上、需要先下载时。
- ✓当我需要提取 PDF 的文字,并希望据此制作新的 PDF 时。
- ✓当 PDF 已在我的电脑上、我只需要提取文字并制作新文档时。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-download-extract-fallback-enhanced-29b2f4/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请从这个链接下载 PDF,提取其中的文字,然后用 reportlab 为我制作一份新的结构化 PDF 摘要。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 用类似浏览器的请求下载文件,检查它是否为真正的 PDF,用现有的最佳工具提取文字,并根据处理后的内容生成新文档。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
PDF Extract and Create Workflow
This skill provides a complete PDF lifecycle workflow for acquiring PDF documents from web sources or local files, extracting their text content, AND generating new structured PDFs from processed data—with multiple fallback mechanisms throughout.
Overview
When working with PDFs, you may need to:
- Download PDFs from web sources (with anti-bot protection)
- Extract text content from PDFs (with fallback strategies)
- Generate new PDFs from processed data (with professional formatting)
This workflow ensures maximum success rate through progressive fallback strategies for extraction and templated approaches for generation.
Entry Point: Determine Your Starting Point
Before beginning, identify your scenario:
| Scenario | Start Here | Skip |
|---|---|---|
| PDF already on local disk | Step 2 (Verify File Type) | Step 1 (Download) |
| PDF at a web URL | Step 1 (Download) | None |
| Need to CREATE a PDF from data | Mode C (Generate) | Modes A & B |
| Need to extract AND create | Mode A/B → Mode C | None |
Mode A: Web URL Download
Step 1: Download PDF with Browser User-Agent
Many PDF hosting sites use JavaScript-based redirects or block automated requests. Use curl with a realistic browser user-agent:
curl -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" -o output.pdf "URL_HERE"
Key flags:
-L: Follow redirects-A: Set user-agent header to mimic a real browser-o: Specify output filename
Additional headers for difficult sites:
curl -L \
-A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" \
-H "Accept: application/pdf,*/*" \
-H "Accept-Language: en-US,en;q=0.9" \
-H "Connection: keep-alive" \
-o output.pdf "URL_HERE"
Mode B: Local File Processing & Extraction
If you already have the PDF file locally, skip Step 1 and begin here:
Step 2: Verify File Type Before Parsing
Always validate the downloaded file is actually a PDF before attempting extraction:
file output.pdf
Expected output should contain "PDF document". If not:
- The URL may have redirected to an HTML error page
- The file may be corrupted
- Access may be blocked
Step 3: Primary Extraction with pdftotext
First attempt extraction using the standard pdftotext utility (part of poppler-utils):
pdftotext output.pdf output.txt
If pdftotext is not available, install it:
# Debian/Ubuntu
apt-get update && apt-get install -y poppler-utils
# macOS
brew install poppler
# RHEL/CentOS
yum install -y poppler-utils
Step 4: Fallback to PyMuPDF (fitz)
If pdftotext fails or produces poor results, use Python's PyMuPDF library:
import fitz # PyMuPDF
doc = fitz.open("output.pdf")
text = ""
for page in doc:
text += page.get_text()
doc.close()
with open("output.txt", "w") as f:
f.write(text)
Install if needed:
pip install pymupdf
Step 5: Graceful Degradation to Domain Knowledge
If the PDF cannot be accessed or extracted after all attempts:
- Document the failure mode (network issue, corrupted file, access denied, etc.)
- Extract any partial content that was successfully retrieved
- Supplement missing content from established domain knowledge
- Clearly mark which portions are from source vs. generated from knowledge
- Provide citations for any claimed requirements or specifications
Example degradation note:
NOTE: Source document [URL] was inaccessible due to [reason].
Content below combines partial extraction with established domain knowledge
for [topic]. Verify against official sources when available.
Mode C: PDF Generation with ReportLab
After extracting or processing data, generate professional PDFs using Python's reportlab library.
Installation
pip install reportlab
Step C1: Basic Document Structure
Create a multi-page PDF with title page, sections, and proper formatting:
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.lib.enums import TA_CENTER, TA_LEFT
def create_structured_pdf(output_path, title, sections):
"""
Create a structured PDF with title page and sections.
常见问题
如果下载被阻止怎么办?
指南使用类似浏览器的请求,并在下载结果不是真正的 PDF 时提供备用方法。
文字是怎样提取的?
指南按顺序尝试多种方法,从简单读取开始,再到 shell 或 Python 工具。
用哪个库生成新 PDF?
指南使用 reportlab 生成新的结构化文档。
详情
作者的原始描述
Complete PDF lifecycle: download, extract, and generate structured documents with reportlab
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12915
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。