【分享】一文搞定 PDF2zh & Zotero‑PDF2zh Prompt 配置(含自用 Prompt)

【分享】一文搞定 PDF2zh & Zotero‑PDF2zh Prompt 配置(含自用 Prompt)

她笑中藏泪花
5月22日发布 /正在检测是否收录...

写在开始

在上一篇博文里,我已经详细介绍了 PDFMathTranslate 这款神器,并给出了常见问题与实用解决方案:

这款工具支持自定义 prompt。趁着空闲时间,我写了一份通用 prompt,已经在日常翻译中跑通,分享给大家。如果在使用过程中遇到问题,欢迎在评论区交流~

注意事项:

  1. Tokens 消耗与费用说明

    • API 调用成本增加:使用该prompt调用大模型,会显著增加 tokens 消耗,进而提升总体费用。
    • 计费参考示例

      • GPT‑4o Mini:$0.01 / 1K tokens
      • GPT‑4:$0.03 / 1K tokens
      • GPT‑3.5 Turbo:$0.002 / 1K tokens
    • 语言差异影响:非英语语言因编码差异,tokens 使用量平均增加约 30%–50%。
    • 翻译“重影”风险提示:使用该 prompt 时可能导致译文与原文重叠或重复的“重影”现象,尤其在复杂排版或 OCR 场景中更为明显。
  2. BabelDOC API 状态提醒

    • 实验性功能提示:BabelDOC 当前仍处于实验阶段,兼容性尚不稳定,可能存在调用失败或翻译文本错误。
    • pdf2zh 2.0 版本预告

      • 可能于近期发布;
      • 将重构整体架构,显著提升性能;
      • 强化对 BabelDOC 的全面支持。

      (2025年05月23日)


使用步骤

1. GUI 界面

  1. 终端输入

    pdf2zh -i
  2. 弹出 GUI 后,选择任意大模型翻译服务,点击 “Open for More Experimental Options!”
  3. “Custom Prompt for llm” 输入框里粘贴下面的 prompt,保存即可。
    image.png

2. 命令行

  1. 将 prompt 复制到 prompt.txt
  2. 运行

    pdf2zh example.pdf --prompt prompt.txt

    --prompt 用来指定需要传给 LLM 的自定义提示词。

  3. 若想使用绝对路径,可直接替换文件路径:

    pdf2zh example.pdf --prompt "C:\Users\YourName\Documents\prompt.txt"

3. Zotero for Pdf2zh

  1. 从仓库下载最新版 server.py
  2. 在文件中找到 cmd = [ ... ];在 '--config', config.configPath, 之后回车换行,追加一行

    '--prompt', './prompt.txt'
  3. prompt.txtserver.py 放在同一目录,或确保脚本能正确定位到文件。

    cmd = [
     config.engine,
     input_path,
     '--t', str(config.threads),
     '--output', config.outputPath,
     '--service', config.service,
     '--lang-in', config.sourceLang,
     '--lang-out', config.targetLang,
     '--config', config.configPath,
     '--prompt', './prompt.txt'  # ← 在此自定义 prompt 路径(注意:\一定要换成/)
    ]

BabelDOC

BabelDOC 是一款开源的 PDF 文档翻译工具,支持命令行和 Python API,便于在脚本中集成。它采用先进的版式保留技术,可以在翻译时完整保留原始排版、公式和图表格式。

大家可能纠结是否启用 BabelDOC。我的建议是:默认关闭。原因如下:
优点:

  • 排版更优:开启后版面确实更美观。
    目前的不足:
  • 复制不便:翻译后的中文复制出来往往是 ASCII 编码,检索极不友好;
    a4df2100fba3a2453247b3a70037dff3.png
    b2a03c247081745745c426ef90e277a6.png
  • 输出易乱:大模型有时会输出诸如 **感受野**v1、v2、v3 等异常格式。
    image.png

权衡之下,我更倾向于关闭,以保证可检索性与稳定性。

prompt

You are a high-precision, professional, and reliable academic machine-translation engine.  
Your task is to produce publication-ready translations that preserve the source document’s structure, formatting, citations, formulas, and scholarly tone—all while adhering to the grammatical and stylistic conventions of the target language.  
Output only the translated text—no annotations, explanations, extra symbols, or any additional text.

<objective>  
Translate the following Markdown source text from ${lang_in} into ${lang_out}, ensuring linguistic precision, lexical accuracy, and syntactic fluency without altering the original logic or structure.  
</objective>

<constraints>  
1. Maintain strict terminological consistency; do not add, omit, merge, or split information.  
2. Preserve all numerical data, units, statistical expressions, and formula notation of the form `{v*}`.  
3. Follow a formal academic register and the style conventions of ${lang_out}. Avoid colloquial language and contractions.  
4. Retain citation formats, reference markers, tables, figure references, and list structures exactly as in the source text.  
5. Keep proper nouns, organisation names, and article titles in their original language form on first mention, followed—if no accepted form exists in ${lang_out}—by an accurate transliteration or translation in parentheses.  
6. Ensure overall coherence, appropriate sentence length, and compliance with grammar and punctuation standards expected by high-quality journals. 
7. Introduce no new sources, interpretations, or commentary; the translation must be strictly faithful and plagiarism-free.
</constraints>

<output_requirements>  
Output only the translated text—no annotations, explanations, extra symbols, or any additional text.
</output_requirements>

Source Text: ${text}

Translated Text:

结语

写到这里,本篇就分享完毕。PDFMathTranslate + 自定义 prompt 绝对是 PDF 翻译提效的「黄金组合」。愿此文能帮你把手头的外文 PDF 统统「秒」成母语,轻松专注于内容本身。如果有任何疑问,别忘了在评论区交流,一起让工作流更丝滑!

© 版权声明
THE END
喜欢就支持一下吧
点赞 0 分享 收藏
评论 抢沙发
OωO
取消