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

pdf-gen-fallback

它能做什么

这项技能提供一种可靠的方法,通过 shell 用 Python 制作 PDF 和报告。它适合文档生成因沙箱含糊的错误而不断失败的人。

适用场景

  • ✓当沙箱在生成 PDF 或报告时返回含糊信息的时候。
  • ✓当我需要在这台电脑上制作 PDF、报告或文档的时候。
  • ✓当 reportlab 等库可能不可用的时候。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-gen-fallback/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请用我的内容制作 PDF 报告。沙箱一直返回含糊的错误,所以请检查库,并用其他方式生成。”

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

工作原理

AI 会先尝试沙箱,留意不透明或导入错误;如果出现这些错误,就检查库,并通过 shell 生成 PDF。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

PDF Generation Fallback

This skill provides a reliable workflow for generating PDFs and documents when execute_code_sandbox returns opaque errors. Use direct run_shell with python -c as a fallback, with library availability checks and explicit error handling.

When to Use

  • execute_code_sandbox fails with cryptic error messages during document/PDF generation
  • You need to generate PDFs, reports, or structured documents
  • Standard library execution is unreliable for document creation tasks

Step-by-Step Procedure

Step 1: Check Library Availability

Before attempting generation, verify that required libraries are installed:

run_shell command="python -c \"import reportlab; print('reportlab available')\""
run_shell command="python -c \"import fpdf; print('fpdf available')\""
run_shell command="python -c \"import pypdf; print('pypdf available')\""

Step 2: Attempt execute_code_sandbox First

Try the sandbox approach initially (it's cleaner for iteration):

execute_code_sandbox code="""
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

c = canvas.Canvas("output.pdf", pagesize=letter)
c.drawString(100, 750, "Document Content")
c.save()
print("ARTIFACT_PATH:/path/to/output.pdf")
"""

Step 3: Detect Opaque Errors

Watch for these failure indicators:

  • Generic "execution failed" messages
  • Import errors that don't match library availability checks
  • Timeout errors during document rendering
  • Missing artifact paths in output

Step 4: Fall Back to run_shell

If sandbox fails, use direct shell execution:

run_shell command="python -c \"
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas('output.pdf', pagesize=letter)
c.drawString(100, 750, 'Document Content')
c.save()
print('PDF created successfully')
\""

Step 5: Verify Output

After generation, confirm the file exists:

run_shell command="ls -la output.pdf && file output.pdf"

Complete Example Workflow

1. Check libraries: run_shell "python -c \"import reportlab\""
2. Try sandbox: execute_code_sandbox with PDF generation code
3. If error detected: Fall back to run_shell with python -c
4. Verify: run_shell "ls -la *.pdf"
5. Read result: read_file filetype="pdf" file_path="output.pdf"

Error Handling Tips

  • Capture stderr from run_shell to diagnose issues
  • Use absolute paths when possible to avoid working directory issues
  • For complex documents, write the Python script to a file first, then execute
  • Consider installing missing libraries: run_shell command="pip install reportlab"

Library Alternatives

If reportlab is unavailable, try:

  • fpdf - Simpler API, good for basic PDFs
  • weasyprint - HTML/CSS to PDF conversion
  • pypdf - PDF manipulation and merging

Common Pitfalls

  • Don't assume sandbox errors mean the approach is wrong—often it's环境 issues
  • Always verify the PDF was created before proceeding
  • Handle encoding issues explicitly (use utf-8)
  • For images in PDFs, ensure image files are accessible to the execution context
常见问题

AI 会先尝试沙箱吗?

会。指南要求先尝试沙箱,因为它更便于反复修改。

失败的迹象有哪些?

通用的执行失败信息、导入错误以及类似的不明确问题。

检查哪些库?

指南检查 reportlab、fpdf 和 pypdf。

详情

作者的原始描述

Reliable PDF generation using shell-based Python execution when sandbox fails

repo: HKUDS/AgentPilot

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能