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

pandoc-pdf-error-resolution

它能做什么

这项技能为错误信息不清楚的 pandoc PDF 转换问题提供了结构化的解决方法。适合转换文档为 PDF 时看到未知错误提示的人。

适用场景

  • ✓当 pandoc 在 PDF 转换时返回未知错误时。
  • ✓当同一份文档能转换为 HTML 或 Markdown,却无法转换为 PDF 时。
  • ✓当我需要找出这台电脑上哪个 PDF 引擎可用时。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pandoc-pdf-error-resolution/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请帮我:pandoc 无法把我的文档转换为 PDF,只提示未知错误。请找出可用的 PDF 引擎并生成文件。”

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

工作原理

AI 检查 pandoc 版本,查找 pdflatex、xelatex、lualatex 和 wkhtmltopdf,用指定的引擎重新转换,并读取错误信息以决定要修改什么。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Pandoc PDF Error Resolution

This skill provides a step-by-step workflow for diagnosing and resolving "unknown error" messages when using pandoc to generate PDFs.

When to Use

Use this skill when:

  • Pandoc returns an "unknown error" during PDF conversion
  • The conversion succeeds for other formats (e.g., markdown, HTML) but fails for PDF
  • You need to identify which PDF engine is available and working

Step-by-Step Procedure

Step 1: Verify Pandoc Installation

First, confirm pandoc is installed and check its version:

pandoc --version

This confirms pandoc is available and shows the version number. Note that pandoc itself doesn't generate PDFs directly—it delegates to external PDF engines.

Step 2: Check Available PDF Engines

Identify which PDF engines are installed on the system:

which pdflatex xelatex lualatex wkhtmltopdf pdfroff 2>/dev/null || echo "Checking individual engines..."
which pdflatex
which xelatex
which lualatex
which wkhtmltopdf

Common engines and their characteristics:

  • pdflatex: Fast, widely available, good for basic documents
  • xelatex: Better Unicode/font support, recommended for complex documents
  • lualatex: Advanced typography, Lua scripting support
  • wkhtmltopdf: HTML-to-PDF conversion, good for web-style documents

Step 3: Attempt Conversion with Explicit Engine

Retry the conversion with an explicit --pdf-engine flag:

pandoc input.md -o output.pdf --pdf-engine=xelatex

Try engines in this order:

  1. xelatex (best Unicode support)
  2. pdflatex (most widely available)
  3. lualatex (if xelatex fails)
  4. wkhtmltopdf (for HTML-heavy content)

Step 4: Capture Full stderr Output

Always capture the complete error output before falling back:

pandoc input.md -o output.pdf --pdf-engine=xelatex 2>&1 | tee pandoc_error.log

This preserves the full error message for analysis. Common error patterns:

  • Font errors: Missing LaTeX packages or fonts
  • Package errors: Missing LaTeX packages (use tlmgr install <package>)
  • Syntax errors: Issues in the source document

Step 5: Install Missing Dependencies (if needed)

If errors indicate missing LaTeX packages:

# For TeX Live
tlmgr install <package-name>

# For Debian/Ubuntu
apt-get install texlive-latex-extra texlive-fonts-recommended

# For macOS with Homebrew
brew install --cask mactex

Step 6: Fallback Strategies

If all engines fail, consider:

  1. Convert to HTML first, then use wkhtmltopdf
  2. Simplify the document (remove complex formatting)
  3. Use an online conversion service
  4. Generate PDF from a different format (e.g., DOCX via LibreOffice)

Example Complete Workflow

#!/bin/bash
# pandoc-pdf-debug.sh

INPUT_FILE="$1"
OUTPUT_FILE="${INPUT_FILE%.md}.pdf"

echo "=== Pandoc PDF Conversion Debug ==="
echo "Input: $INPUT_FILE"
echo "Output: $OUTPUT_FILE"

# Step 1: Verify pandoc
echo -e "\n[1] Checking pandoc version..."
pandoc --version | head -1

# Step 2: Check engines
echo -e "\n[2] Checking available PDF engines..."
for engine in pdflatex xelatex lualatex wkhtmltopdf; do
    if which "$engine" &>/dev/null; then
        echo "  ✓ $engine: $(which $engine)"
    else
        echo "  ✗ $engine: not found"
    fi
done

# Step 3: Try conversion with xelatex
echo -e "\n[3] Attempting conversion with xelatex..."
pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" --pdf-engine=xelatex 2>&1 | tee /tmp/pandoc_error.log

if [ $? -eq 0 ]; then
    echo "✓ Conversion successful!"
else
    echo "✗ Conversion failed. Check /tmp/pandoc_error.log for details"
    echo "Attempting fallback with pdflatex..."
    pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" --pdf-engine=pdflatex 2>&1
fi

Quick Reference

Command Purpose
pandoc --version Verify pandoc installation
which xelatex Check if xelatex engine exists
pandoc file.md -o file.pdf --pdf-engine=xelatex Convert with explicit engine
... 2>&1 | tee error.log Capture full stderr output
tlmgr install <pkg> Install missing LaTeX package
常见问题

pandoc 自己能生成 PDF 吗?

不能。指南说明 pandoc 会把生成工作交给外部 PDF 引擎完成。

为什么要检查其他格式?

如果其他格式可以正常转换,问题很可能出在 PDF 引擎,而不是文档本身。

哪个引擎对 Unicode 更好?

指南称 xelatex 比 pdflatex 具有更好的 Unicode 和字体支持。

详情

作者的原始描述

Systematic debugging workflow for pandoc PDF conversion errors

repo: HKUDS/AgentPilot

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能