pdf-generation-troubleshooting
What it does
This skill is a three-step plan for PDF creation that falls back from pandoc to Python libraries. It is for people converting Markdown or building PDFs when some tools may be missing.
When to use it
- ✓When I have a Markdown or HTML file that must become a PDF.
- ✓When pandoc is missing or fails on the conversion.
- ✓When I need a PDF built from scratch with Python because the other tools are unavailable.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-generation-troubleshooting/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Turn this Markdown into a PDF. If pandoc is not available here, use a Python library instead.”
5 new skills a week. 1 minute to read.
How it works
The AI checks for pandoc and converts if it is present. If not, it checks for reportlab and installs it if needed, and finally tries fpdf2.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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:
# 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
| 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
# 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
FAQ
What is the first choice?
Pandoc, which is the simplest option for Markdown or HTML files.
What comes after pandoc?
Reportlab, a Python library, and then fpdf2 if reportlab does not work.
Are tools checked before use?
Yes, each step checks installation before running.
Details
Original description by the author
Systematic fallback workflow for PDF generation through pandoc, reportlab, and fpdf2 with installation verification
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #12929
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
feishu-doc
394kHelps your agent read, create, and edit Feishu cloud documents, including text, images, and tables, using the document tool.
feishu-drive
394kLets your agent browse, organize, and comment on files in a Feishu cloud folder that has been shared with the bot.
feishu-perm
394kHelps your agent check and change who can access a Feishu file, choosing the smallest permission that meets your request.