跳到正文
Skillpedia
PDF、Word 与幻灯片7.8k · #12936

pdf-verification-check-112b09

它能做什么

这项技能确认 AI 制作的 PDF 确实存在、不是空文件,并且页数正确。它适合在使用 PDF 之前需要确信其有效性的人。

适用场景

  • ✓当任务生成了一个 PDF,需要在完成前进行检查的时候。
  • ✓当 PDF 需要特定页数的时候。
  • ✓当任务生成了多个 PDF 输出,且都需要检查的时候。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-verification-check-112b09/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-verification-check-112b09/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“制作完 PDF 后,请检查文件是否存在、是否不为空,并确认它恰好有三页。”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会在需要时安装 PyPDF2,运行一个简短的 Python 函数,确认文件存在、有内容,并符合预期页数,然后汇报结果。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

PDF Verification Check

After generating PDF files, always programmatically verify their structure and integrity before declaring task completion. This catches formatting errors, incorrect page counts, and corrupted files early.

When to Use

Use this skill whenever your task involves:

  • Generating PDF documents
  • Creating PDFs with specific page count requirements
  • Producing multi-part PDF outputs (e.g., listings + maps)

Verification Steps

1. Install PyPDF2 (if not available)

pip install PyPDF2

2. Verify PDF Page Count and Integrity

Create a verification script or run inline Python:

from PyPDF2 import PdfReader
import os

def verify_pdf(pdf_path, expected_pages=None):
    """Verify PDF file exists, is readable, and has expected page count."""
    try:
        # Check file exists
        if not os.path.exists(pdf_path):
            return False, f"File not found: {pdf_path}"
        
        # Check file size (non-empty)
        file_size = os.path.getsize(pdf_path)
        if file_size == 0:
            return False, f"Empty file: {pdf_path}"
        
        # Open and verify PDF structure
        reader = PdfReader(pdf_path)
        actual_pages = len(reader.pages)
        
        # Check page count if expected
        if expected_pages is not None and actual_pages != expected_pages:
            return False, f"Expected {expected_pages} pages, got {actual_pages}"
        
        return True, f"Valid PDF with {actual_pages} page(s)"
        
    except Exception as e:
        return False, f"PDF verification failed: {str(e)}"

# Example usage
pdf_files = [
    ("listings.pdf", 2),
    ("map.pdf", 1),
]

all_valid = True
for pdf_path, expected in pdf_files:
    valid, message = verify_pdf(pdf_path, expected)
    print(f"{pdf_path}: {'✓' if valid else '✗'} {message}")
    if not valid:
        all_valid = False

if not all_valid:
    raise Exception("PDF verification failed - review and regenerate")

3. Use run_shell for Verification

Execute the verification using run_shell:

python -c "
from PyPDF2 import PdfReader
import sys

pdf_path = 'output.pdf'
expected = 2

try:
    reader = PdfReader(pdf_path)
    actual = len(reader.pages)
    if actual != expected:
        print(f'ERROR: Expected {expected} pages, got {actual}')
        sys.exit(1)
    print(f'OK: {pdf_path} has {actual} page(s)')
except Exception as e:
    print(f'ERROR: {e}')
    sys.exit(1)
"

4. Verify Before Completion

Critical: Only mark your task as complete after ALL PDF verification checks pass. If verification fails:

  1. Examine the error message
  2. Regenerate the PDF with corrected formatting
  3. Re-run verification
  4. Repeat until all checks pass

Common Issues Caught

  • Wrong page counts (e.g., content spilling to extra pages)
  • Empty or corrupted PDF files
  • PDFs that fail to open properly
  • Missing expected sections due to formatting errors

Example Workflow

# 1. Generate PDF
generate_pdf("listings.pdf", content)

# 2. Verify before completion
valid, msg = verify_pdf("listings.pdf", expected_pages=2)
if not valid:
    # Fix and regenerate
    regenerate_pdf("listings.pdf", corrected_content)
    valid, msg = verify_pdf("listings.pdf", expected_pages=2)

# 3. Only complete if verification passes
assert valid, f"Cannot complete: {msg}"
常见问题

这项检查确认什么?

文件存在、不为空,并且能以预期的页数打开。

PyPDF2 用来做什么?

它打开 PDF 并统计页数。

如果页数不对怎么办?

检查会报告不一致,以便 AI 修复生成步骤。

详情

作者的原始描述

Verify generated PDF files using PyPDF2 to check page counts and integrity

repo: HKUDS/AgentPilot

热度

GitHub 星标
7.8k
排名
#12936
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能