document-gen-resilient-workflow
What it does
This skill guides the AI in producing documents such as Word, PDF or HTML files, with fallbacks when a tool breaks. It is for people who need a reliable document, especially one with special characters.
When to use it
- ✓When PDF creation fails because of missing LaTeX or encoding errors.
- ✓When a document must come out in several formats from one source.
- ✓When the text contains symbols or non-English characters that break the conversion.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/document-gen-fallback-enhanced-enhanced-2794b4/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
“I need my notes turned into a Word file and a PDF, and I need the accented characters to display correctly.”
5 new skills a week. 1 minute to read.
How it works
The AI writes the content in Markdown, cleans up special characters where needed, tries PDF engines one after another until one works, and checks that the output file is valid.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Resilient Document Generation Workflow (Multi-Engine Fallback)
When to Use
Use this skill when document generation tasks fail or when shell_agent returns unknown errors, especially for:
- Generating documents in multiple formats (
.docx,.pdf,.html) - PDF generation fails due to missing LaTeX, encoding issues, or tool errors
- Documents contain special characters, symbols, or non-ASCII text
- You need maximum reliability with automatic fallback options
Core Technique
Split document generation into discrete, observable steps with cascading fallbacks for PDF generation:
- Content creation → Use
write_fileto create source Markdown - Unicode sanitization → Use Python script for reliable character replacement
- Format conversion → Try multiple PDF engines in sequence until one succeeds
- Verification → Check file exists, has non-zero size, and is valid
⚠️ Unicode & PDF Engine Guide
Different PDF engines have different Unicode support:
| Engine | Unicode Support | Best For | Fallback Position |
|---|---|---|---|
pdflatex |
Limited (ASCII-focused) | Simple documents | 1st (fastest) |
xelatex |
Full Unicode | Documents with non-ASCII | 2nd |
wkhtmltopdf |
Good Unicode | Web-style documents | 3rd |
reportlab (Python) |
Full control | Programmatic PDFs | 4th |
fpdf2 (Python) |
Full control | Simple text PDFs | 5th (last resort) |
Character Replacement Table
| Character | Issue | Safe Replacement |
|---|---|---|
— (em dash) |
LaTeX incompatibility | -- |
– (en dash) |
LaTeX incompatibility | - |
" " (curly quotes) |
Encoding errors | " " (straight) |
' ' (curly apostrophe) |
Encoding errors | ' (straight) |
… (ellipsis) |
May not render | ... |
→ ← ↑ ↓ |
LaTeX incompatibility | -> <- ^ v |
✓ ✗ |
May not render | [x] [ ] |
★ ● |
May not render | * - |
© ® ™ |
May require packages | (c) (r) (tm) |
é ñ ü |
Font-dependent | Keep for xelatex, replace for pdflatex |
Step-by-Step Workflow
Step 1: Create Source Content with write_file
Write your document content as Markdown to a source file:
write_file
path: /tmp/document_source.md
content: |
# Document Title
## Section 1
Content here...
## Section 2
More content...
Step 2: Sanitize Unicode with Python Script
Create a reusable Python sanitizer for reliable character replacement:
write_file
path: /tmp/sanitize_unicode.py
content: |
#!/usr/bin/env python3
import sys
import re
if len(sys.argv) < 2:
print("Usage: sanitize_unicode.py <input.md> [output.md]")
sys.exit(1)
input_file = sys.argv[1]
output_file = sys.argv[2] if len(sys.argv) > 2 else input_file.replace('.md', '_sanitized.md')
replacements = {
'—': '--', # em dash
'–': '-', # en dash
'"': '"', # left curly quote
'"': '"', # right curly quote
"'": "'", # left curly apostrophe
"'": "'", # right curly apostrophe
'…': '...', # ellipsis
'→': '->', # right arrow
'←': '<-', # left arrow
'↑': '^', # up arrow
'↓': 'v', # down arrow
'✓': '[x]', # checkmark
'✗': '[ ]', # cross
'★': '*', # star
'●': '-', # bullet
'©': '(c)', # copyright
'®': '(r)', # registered
'™': '(tm)', # trademark
}
with open(input_file, 'r', encoding='utf-8') as f:
content = f.read()
for old, new in replacements.items():
content = content.replace(old, new)
with open(output_file, 'w', encoding='utf-8') as f:
f.write(content)
print(f"Sanitized: {input_file} -> {output_file}")
Apply sanitization for PDF:
run_shell
command: python3 /tmp/sanitize_unicode.py /tmp/document_source.md /tmp/document_source_sanitized.md
Note: Keep original for DOCX/HTML (these formats handle Unicode well).
Step 3: Convert to Target Formats with Cascading Fallbacks
For DOCX (from original, no sanitization needed):
run_shell
command: pandoc /tmp/document_source.md -o output.docx
For PDF (try multiple engines in sequence):
Attempt 1: pdflatex (fastest, limited Unicode)
run_shell
command: pandoc /tmp/document_source_sanitized.md -o output.pdf --pdf-engine=pdflatex
*If pdflatex fails, Attempt 2: xelatex (full Unicode)
FAQ
Which PDF engines does it try?
The guide lists pdflatex, xelatex, wkhtmltopdf, reportlab and fpdf2 as options in a set order.
Why does Unicode support matter?
Some PDF engines handle non-ASCII characters poorly, so the guide explains which engine to use.
Does it check the result?
Yes, the guide says to confirm the file exists, has content and is valid.
Details
Original description by the author
Multi-engine document generation with cascading PDF fallbacks and robust Unicode handling
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #12856
- 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.