| name | pdf-verification-check |
| description | Verify generated PDFs for integrity and page count using PyPDF2 before task completion. |
PDF Verification Check
Use this skill whenever your task involves generating PDF files. Do not declare task completion until you have programmatically verified that the PDFs exist, are not corrupted, and match the expected page counts.
When to Use
- Immediately after generating one or more PDF files.
- Before reporting success or moving to the next phase of a task.
- When specific page counts are required (e.g., "1-page summary", "2-page listing").
Verification Steps
- Identify Expected Outputs: List the file paths and their expected page counts.
- Run Verification Script: Use
run_shell to execute a Python script using PyPDF2.
- Validate Results: Ensure the script exits successfully and reports the correct page counts.
- Remediate: If verification fails, inspect the generation logic and regenerate.
Verification Script
Use the following Python snippet with run_shell to verify PDFs. Adjust the expected_pages dictionary to match your task requirements.
import sys
from PyPDF2 import PdfReader
def verify_pdfs(files):
"""
files: dict mapping filepath to expected_page_count (or None if any count is ok)
"""
all_valid = True
for path, expected_count files.items():
:
reader = PdfReader(path)
actual_count = (reader.pages)
expected_count actual_count != expected_count:
()
all_valid =
:
()
Exception e:
()
all_valid =
all_valid
files_to_check = {
: ,
:
}
sys.exit(verify_pdfs(files_to_check))