<< All versions
Skill v1.0.2
currentAutomated scan100/100hkuds/openspace/pdf-generation-troubleshooting
1 files
──Details
PublishedApril 26, 2026 at 05:12 PM
Content Hashsha256:5ffbfddbe5097111...
Git SHAd1e367d0ed47
Bump Typepatch
──Files
Files (1 file, 3.6 KB)
SKILL.md3.6 KBactive
SKILL.md · 157 lines · 3.6 KB
version: "1.0.2" name: pdf-generation-troubleshooting description: Systematic fallback workflow for PDF generation through pandoc, reportlab, and fpdf2 with installation verification
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
- Try pandoc first (simplest for markdown/HTML conversion)
- Fallback to reportlab (Python library for programmatic PDFs)
- 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:
bash
# Check if pandoc is availablewhich pandoc || echo "pandoc not found"
If available, convert:
bash
pandoc input.md -o output.pdf
If pandoc fails or is unavailable, proceed to Step 2.
Step 2: Attempt reportlab
Check Installation
bash
python3 -c "import reportlab" 2>/dev/null && echo "reportlab available" || echo "reportlab not found"
Install if Needed
bash
pip install reportlab
Create PDF Script
Use write_file to create a Python script:
python
from reportlab.lib.pagesizes import letterfrom reportlab.pdfgen import canvasdef 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:
bash
cd /path/to/working/directory && python3 script.py
If reportlab fails, proceed to Step 3.
Step 3: Attempt fpdf2
Check Installation
bash
python3 -c "from fpdf import FPDF" 2>/dev/null && echo "fpdf2 available" || echo "fpdf2 not found"
Install if Needed
bash
pip install fpdf2
Create PDF Script
python
from fpdf import FPDFdef 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
bash
cd /path/to/working/directory && python3 script.py
Decision Matrix
| Tool | Best For | Limitations | |
|---|---|---|---|
| pandoc | Markdown/HTML conversion | Requires external installation | |
| reportlab | Complex layouts, graphics | Steeper learning curve | |
| fpdf2 | Simple text PDFs | Limited formatting options |
Error Handling Pattern
For each tool attempt:
- Check availability/installation
- Install if missing (
pip install <package>) - Create script using
write_file - Execute using
run_shellwithcd <dir> && <command> - Verify output file exists
- If fails, move to next tool in sequence
Example Fallback Implementation
bash
# Pseudocode for full workflowif command -v pandoc >/dev/null 2>&1; thenpandoc input.md -o output.pdf && exit 0fiif python3 -c "import reportlab" 2>/dev/null; then# Create and run reportlab scriptexit 0fi# Final fallback: fpdf2pip 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