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

pdf-engine-fallback

它能做什么

这项技能是 pandoc 生成 PDF 的重试方案,当默认引擎失败时会尝试其他引擎。它适合用于处理非英文或含特殊字符的文档,或自动化流程中的人。

适用场景

  • ✓当 pandoc 生成 PDF 时出现错误的时候。
  • ✓当文档包含重音字母或非拉丁文字等非 ASCII 文本的时候。
  • ✓当我的文档流程需要在配置不同的电脑上生成 PDF 的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“pandoc 无法把我的文档制作成 PDF,文档中包含带重音的字母和中文。请检查可用的引擎,并换一个能处理这些字符的引擎重试。”

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

工作原理

AI 会先尝试默认转换;失败时检查已安装的 PDF 引擎,然后根据内容选用合适的引擎重试,例如用 xelatex 处理 Unicode,或用 wkhtmltopdf 处理网页式版面。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

PDF Engine Fallback

This skill provides a diagnostic-retry workflow for PDF generation when Pandoc's default PDF engine fails. It systematically checks available engines and retries with alternatives optimized for different content types (e.g., xelatex for Unicode).

When to Use

  • Pandoc PDF generation fails with errors
  • Document contains non-ASCII characters (Unicode, CJK, etc.)
  • Need robust PDF generation across different system configurations
  • Working in CI/CD or automated document pipelines

Steps

1. Attempt Initial PDF Generation

First, try generating with pandoc's default engine:

pandoc input.md -o output.pdf

2. Diagnose on Failure

If the initial attempt fails, check which PDF engines are available:

# Check for pdflatex
which pdflatex && echo "pdflatex: available" || echo "pdflatex: not found"

# Check for xelatex (better Unicode support)
which xelatex && echo "xelatex: available" || echo "xelatex: not found"

# Check for wkhtmltopdf (HTML-based rendering)
which wkhtmltopdf && echo "wkhtmltopdf: available" || echo "wkhtmltopdf: not found"

3. Retry with Alternative Engine

Based on available engines and document content, retry with an appropriate engine:

# For documents with Unicode/special characters - prefer xelatex
pandoc input.md -o output.pdf --pdf-engine=xelatex

# Alternative: use pdflatex for simple Latin documents
pandoc input.md -o output.pdf --pdf-engine=pdflatex

# For HTML-heavy content or complex layouts
pandoc input.md -o output.pdf --pdf-engine=wkhtmltopdf

4. Handle Missing Engines

If no PDF engines are available, install one:

# Ubuntu/Debian - install texlive with xelatex
sudo apt-get install texlive-xetex

# Or install minimal teTeX
sudo apt-get install texlive-latex-base texlive-latex-extra

# macOS with Homebrew
brew install basictex

Complete Fallback Script

#!/bin/bash
# pdf-fallback.sh - Robust PDF generation with engine fallback

INPUT_FILE="${1:-input.md}"
OUTPUT_FILE="${2:-output.pdf}"

echo "Attempting PDF generation: $INPUT_FILE -> $OUTPUT_FILE"

# Try default engine first
if pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" 2>/dev/null; then
    echo "SUCCESS: PDF generated with default engine"
    exit 0
fi

echo "Default engine failed. Checking available engines..."

# Check and try engines in priority order
if command -v xelatex &>/dev/null; then
    echo "Retrying with xelatex (Unicode support)..."
    if pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" --pdf-engine=xelatex; then
        echo "SUCCESS: PDF generated with xelatex"
        exit 0
    fi
fi

if command -v pdflatex &>/dev/null; then
    echo "Retrying with pdflatex..."
    if pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" --pdf-engine=pdflatex; then
        echo "SUCCESS: PDF generated with pdflatex"
        exit 0
    fi
fi

if command -v wkhtmltopdf &>/dev/null; then
    echo "Retrying with wkhtmltopdf..."
    if pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" --pdf-engine=wkhtmltopdf; then
        echo "SUCCESS: PDF generated with wkhtmltopdf"
        exit 0
    fi
fi

echo "FAILURE: No available PDF engine succeeded"
echo "Install a PDF engine (texlive-xetex recommended) and retry"
exit 1

Usage

# Make executable
chmod +x pdf-fallback.sh

# Run with defaults (input.md -> output.pdf)
./pdf-fallback.sh

# Run with custom files
./pdf-fallback.sh report.md report.pdf

Engine Selection Guide

Engine Best For Unicode Speed
xelatex Non-Latin scripts, modern fonts Excellent Moderate
pdflatex Simple Latin documents Limited Fast
wkhtmltopdf HTML/CSS styling Good Fast

Troubleshooting

  • Font errors: Install required fonts or use xelatex with system fonts
  • Package errors: Install missing LaTeX packages via tlmgr
  • Large documents: Try pdflatex for speed, xelatex for compatibility
  • Citation issues: Ensure pandoc-citeproc or citeproc is installed
常见问题

为什么用 xelatex 处理 Unicode?

指南说,xelatex 完整支持 Unicode,适合带重音和非拉丁文字的内容。

如何检查引擎?

AI 会对每个引擎运行 which 命令,查看是否已安装。

什么时候使用 pdflatex?

指南建议把它用于只有普通拉丁文字的简单文档。

详情

作者的原始描述

Retry PDF generation with alternative engines when pandoc fails

repo: HKUDS/AgentPilot

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能