跳到正文
cccskills
免费在 GitHub 公开

pdf-generation-troubleshooting

Troubleshoot PDF creation by trying pandoc, then reportlab, then fpdf2. Check tool availability, install missing Python libraries as needed, run generation with an explicit working directory, and verify that the output file exists.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Systematic fallback workflow for PDF generation through pandoc, reportlab, and fpdf2 with installation verification

查看安装方法

适用场景

  • Converting Markdown or HTML to PDF
  • Trying another tool after PDF generation fails
  • Checking PDF tools and installing missing libraries
  • Verifying working directories and generated PDFs

包含的文件(2)

  • SKILL.md3.6 KB
  • .skill_id44 B

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

PDF Generation Troubleshooting Workflow

This skill provides a systematic approach to generating PDFs when multiple tools may be unavailable. Follow this fallback sequence to ensure PDF generation succeeds.

Workflow Overview

  1. Try pandoc first (simplest for markdown/HTML conversion)
  2. Fallback to reportlab (Python library for programmatic PDFs)
  3. Fallback to fpdf2 (alternative Python PDF library)

Each step includes installation verification before execution.

Step 1: Attempt pandoc Conversion

Use pandoc for markdown or HTML to PDF conversion. Check availability first:

# Check if pandoc is available
which pandoc || echo "pandoc not found"

If available, convert:

pandoc input.md -o output.pdf

If pandoc fails or is unavailable, proceed to Step 2.

Step 2: Attempt reportlab

Check Installation

python3 -c "import reportlab" 2>/dev/null && echo "reportlab available" || echo "reportlab not found"

Install if Needed

pip install reportlab

Create PDF Script

Use write_file to create a Python script:

from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

def create_pdf(filename, content):
    c = canvas.Canvas(filename, pagesize=letter)
    c.drawString(100, 750, content)
    c.save()

if __name__ == "__main__":
    create_pdf("output.pdf", "Your content here")

Execute Script

Use run_shell with proper directory context:

cd /path/to/working/directory && python3 script.py

If reportlab fails, proceed to Step 3.

Step 3: Attempt fpdf2

Check Installation

python3 -c "from fpdf import FPDF" 2>/dev/null && echo "fpdf2 available" || echo "fpdf2 not found"

Install if Needed

pip install fpdf2

Create PDF Script

from fpdf import FPDF

def create_pdf(filename, text):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Arial", size=12)
    pdf.cell(200, 10, txt=text, ln=True)
    pdf.output(filename)

if __name__ == "__main__":
    create_pdf("output.pdf", "Your content here")

Execute Script

cd /path/to/working/directory && python3 script.py

Decision Matrix

ToolBest ForLimitations
pandocMarkdown/HTML conversionRequires external installation
reportlabComplex layouts, graphicsSteeper learning curve
fpdf2Simple text PDFsLimited formatting options

Error Handling Pattern

For each tool attempt:

  1. Check availability/installation
  2. Install if missing (pip install <package>)
  3. Create script using write_file
  4. Execute using run_shell with cd <dir> && <command>
  5. Verify output file exists
  6. If fails, move to next tool in sequence

Example Fallback Implementation

# Pseudocode for full workflow
if command -v pandoc >/dev/null 2>&1; then
    pandoc input.md -o output.pdf && exit 0
fi

if python3 -c "import reportlab" 2>/dev/null; then
    # Create and run reportlab script
    exit 0
fi

# Final fallback: fpdf2
pip install fpdf2
# Create and run fpdf2 script

Key Principles

  • Always verify tool availability before attempting use
  • Install on-demand when a tool is missing
  • Use write_file for script creation (ensures clean, versionable code)
  • Use run_shell with explicit directory context (cd <dir> && <cmd>)
  • Progressive fallback ensures at least one method succeeds
  • Verify output after each attempt before moving to next tool

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Prepare audio stems, the separate parts of a track, for mixing by matching their durations with silence, loops, or crossfades. Verify each generated and processed file before moving to the next production step.

中文简介正在准备中。当前显示英语简介。

  • Match audio parts with different durations
  • Extend drums and melodic parts using suitable methods
  • Check audio specifications before mixing
HKUDS/OpenSpace77602026年8月13日 更新

Produce audio in separate stems, meaning individual instrument tracks, and verify each output as you go. Align track lengths with silence, loops, or crossfades, then apply effects, mix a master, and package the files.

中文简介正在准备中。当前显示英语简介。

  • Align instrument tracks to a reference audio file
  • Choose how to extend tracks that are too short
  • Verify audio properties after generation and effects
HKUDS/OpenSpace77602026年8月13日 更新

Build serverless endpoints that relay external API requests for a dashboard while keeping API keys on the server. Includes Vercel examples for input checks, caching, cross-origin access, and consistent JSON responses.

中文简介正在准备中。当前显示英语简介。

  • Connect a dashboard to external APIs without exposing API keys
  • Create endpoints for stock quotes and news
  • Standardize API responses and error handling
HKUDS/OpenSpace77602026年8月13日 更新

Produce a master track and separate audio parts through a structured Python workflow. Apply filters and reverb, export WAV files with consistent settings, package them in a ZIP archive, and check that the deliverables meet the requested specifications.

中文简介正在准备中。当前显示英语简介。

  • Export a master track with separate audio parts
  • Apply filters and reverb to audio
  • Check duration and format across deliverables
HKUDS/OpenSpace77602026年8月13日 更新

Keep document creation moving when web searches and page retrieval repeatedly fail. The skill preserves the original task, uses the model’s existing knowledge, and clearly identifies information that could not be checked against external sources.

中文简介正在准备中。当前显示英语简介。

  • Continue drafting after repeated web retrieval failures
  • Preserve task requirements during network errors
  • Mark information that could not be externally verified
HKUDS/OpenSpace77602026年8月13日 更新

When Python execution repeatedly fails in execute_code_sandbox, use a file-based alternative: save the script, run it through the shell, and capture results or errors. The guidance covers paths, imports, timeouts, structured output, and optional cleanup.

中文简介正在准备中。当前显示英语简介。

  • Retry Python work through the shell after repeated sandbox failures
  • Run longer tasks with an adjusted timeout
  • Execute Python work that needs multiple files or system utilities
HKUDS/OpenSpace77602026年8月13日 更新

查看 HKUDS 的全部技能

报告此技能的问题