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

document-gen-resilient-workflow

它能做什么

这项技能指导 AI 制作 Word、PDF 或 HTML 等文档,并在工具出错时提供备用方案。它适合需要可靠文档的人,尤其是包含特殊字符的文档。

适用场景

  • ✓当 PDF 制作因缺少 LaTeX 或编码错误而失败的时候。
  • ✓当同一份内容需要以多种格式输出的时候。
  • ✓当文本中的符号或非英文字符导致转换出错的时候。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/document-gen-fallback-enhanced-enhanced-2794b4/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“我需要把我的笔记转换成 Word 文件和 PDF 文件,并且要确保带重音符号的字符能正确显示。”

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

工作原理

AI 会先用 Markdown 撰写内容,必要时清理特殊字符,然后依次尝试各个 PDF 引擎,直到有一个成功,并检查输出文件是否有效。

技术内容(原始 SKILL.md)

作者在 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:

  1. Content creation → Use write_file to create source Markdown
  2. Unicode sanitization → Use Python script for reliable character replacement
  3. Format conversion → Try multiple PDF engines in sequence until one succeeds
  4. 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)

常见问题

它会尝试哪些 PDF 引擎?

指南按固定顺序列出了 pdflatex、xelatex、wkhtmltopdf、reportlab 和 fpdf2 作为选项。

为什么 Unicode 支持很重要?

有些 PDF 引擎处理非 ASCII 字符的能力较差,因此指南说明了应使用哪个引擎。

它会检查结果吗?

会。指南要求确认文件存在、有内容且有效。

详情

作者的原始描述

Multi-engine document generation with cascading PDF fallbacks and robust Unicode handling

repo: HKUDS/AgentPilot

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能