Chuyển đến nội dung
Skillpedia
PDF, Word và slide7.8k · #12920

pdf-engine-fallback

Skill này làm gì

Skill này là kế hoạch thử lại việc tạo PDF bằng pandoc, thử các engine khác khi engine mặc định thất bại. Dành cho người tạo PDF từ tài liệu có ký tự không phải tiếng Anh hoặc ký tự đặc biệt, hoặc trong quy trình tự động.

Khi nào nên dùng

  • ✓Khi việc tạo PDF bằng pandoc thất bại với một lỗi.
  • ✓Khi tài liệu có văn bản không phải ASCII như chữ có dấu hoặc chữ không dùng bảng chữ cái Latinh.
  • ✓Khi quy trình tài liệu của tôi phải tạo PDF trên các máy tính với thiết lập khác nhau.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-engine-fallback/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Pandoc không tạo được PDF từ tài liệu của tôi, có chữ có dấu và chữ Trung Quốc. Hãy kiểm tra các engine và thử lại với engine xử lý được những ký tự đó.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI thử chuyển đổi mặc định trước, khi thất bại thì kiểm tra các PDF engine đã được cài, rồi thử lại với engine phù hợp nội dung, như xelatex cho Unicode hoặc wkhtmltopdf cho bố cục kiểu web.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

Vì sao dùng xelatex cho Unicode?

Hướng dẫn nói xelatex hỗ trợ đầy đủ Unicode, phù hợp với văn bản có dấu và không phải Latinh.

Các engine được kiểm tra thế nào?

AI chạy lệnh which cho từng engine để xem nó có được cài không.

Khi nào dùng pdflatex?

Hướng dẫn gợi ý pdflatex cho tài liệu đơn giản chỉ có văn bản Latinh thuần.

Chi tiết

Mô tả gốc của tác giả

Retry PDF generation with alternative engines when pandoc fails

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#12920
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự