pdf-verification
它能做什么
这项技能在 PDF 制作完成后立即检查,以发现页数错误、空白页或文件损坏等问题。它适合在使用 PDF 之前需要确信输出质量的人。
适用场景
- ✓当 PDF 生成任务刚刚完成的时候。
- ✓当任务要求特定页数的时候。
- ✓当我希望在完成前确认 PDF 不是空的或已损坏的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-verification/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我需要这份 PDF 是两页。制作完成后,请验证页数,并确保它能正常打开。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会在需要时安装 PyPDF2,通过 run_shell 运行一个简短的检查,打开文件,将页数与目标比较,并报告任何不一致。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
PDF Verification Skill
Purpose
After generating PDF files, always verify page counts and file integrity programmatically before declaring task completion. This catches formatting issues, empty pages, and corrupted files early.
When to Use
- After any PDF generation task
- When specific page counts are required
- Before marking a PDF-related task as complete
Verification Steps
1. Install PyPDF2 (if needed)
pip install PyPDF2
2. Verify Page Count and Integrity
Use run_shell to execute a Python verification script:
python -c "
from PyPDF2 import PdfReader
import sys
def verify_pdf(filepath, expected_pages=None):
try:
reader = PdfReader(filepath)
actual_pages = len(reader.pages)
print(f'✓ {filepath}: {actual_pages} pages')
if expected_pages and actual_pages != expected_pages:
print(f'✗ Page count mismatch: expected {expected_pages}, got {actual_pages}')
return False
# Check file is not empty/corrupted
if actual_pages == 0:
print(f'✗ Empty PDF: {filepath}')
return False
return True
except Exception as e:
print(f'✗ Error reading {filepath}: {e}')
return False
# Verify each PDF
results = []
results.append(verify_pdf('output.pdf', expected_pages=2))
print(f'All checks passed: {all(results)}')
sys.exit(0 if all(results) else 1)
"
3. Verify Multiple PDFs
For tasks with multiple PDFs, verify each one:
python -c "
from PyPDF2 import PdfReader
pdfs = {
'listings.pdf': 2,
'map.pdf': 1,
'summary.pdf': 1
}
all_passed = True
for filepath, expected in pdfs.items():
try:
reader = PdfReader(filepath)
actual = len(reader.pages)
status = '✓' if actual == expected else '✗'
print(f'{status} {filepath}: {actual}/{expected} pages')
if actual != expected:
all_passed = False
except Exception as e:
print(f'✗ {filepath}: {e}')
all_passed = False
print(f'Verification: {\"PASSED\" if all_passed else \"FAILED\"}')
"
4. Check File Size (Optional)
Add file size validation to catch empty or near-empty files:
python -c "
import os
from PyPDF2 import PdfReader
filepath = 'output.pdf'
min_size = 1000 # minimum bytes
file_size = os.path.getsize(filepath)
if file_size < min_size:
print(f'✗ File too small: {file_size} bytes')
else:
reader = PdfReader(filepath)
print(f'✓ {filepath}: {len(reader.pages)} pages, {file_size} bytes')
"
Best Practices
- Verify immediately after generation - Don't wait until the end of the task
- Check all required PDFs - Verify each file meets specifications
- Fail fast - If verification fails, regenerate before proceeding
- Log results - Print verification results for debugging
- Set reasonable minimums - Use file size checks to catch empty outputs
Common Issues Caught
- Wrong page counts (extra blank pages, missing content)
- Corrupted or unreadable PDF files
- Empty PDFs (0 pages)
- Files that appear generated but contain no actual content
Example Task Completion Check
# Final verification before marking task complete
python -c "
from PyPDF2 import PdfReader
import sys
required = {'listings.pdf': 2, 'map.pdf': 1}
passed = True
for f, pages in required.items():
try:
actual = len(PdfReader(f).pages)
if actual != pages:
print(f'FAIL: {f} has {actual} pages, expected {pages}')
passed = False
except Exception as e:
print(f'FAIL: Cannot read {f}: {e}')
passed = False
if passed:
print('SUCCESS: All PDFs verified')
sys.exit(0)
else:
sys.exit(1)
"
常见问题
它能发现空的 PDF 吗?
能。脚本会把零页的 PDF 报告为空文件。
不一致时会怎样?
检查会打印预期和实际的页数,问题一目了然。
应该在什么时候进行检查?
在生成 PDF 之后、标记任务完成之前。
详情
作者的原始描述
Verify PDF page counts and file integrity programmatically using PyPDF2 after generation
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12941
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。