Skip to main content

首页 / Posts

[Share] PDF2zh and Zotero-PDF2zh Prompt Configuration, Including My Own Prompt for pdf2zh 2.x

Use custom prompts in PDFMathTranslate and Zotero for pdf2zh to improve academic translation quality while preserving structure, formatting, citations, and formulas.

Rosetears·
··598 words·3 mins

Opening notes
#

In previous posts I introduced PDFMathTranslate and Zotero-pdf2zh in detail:

The tool supports custom prompts. I wrote a general-purpose prompt that has worked in my daily translation workflow, and I am sharing it here. If you run into issues, feel free to discuss them in the comments.

Notes:

  1. Token cost
    • Using a custom prompt with a large model will significantly increase token consumption and total cost.
    • Example prices: GPT-4o Mini at about $0.01 / 1K tokens, GPT-4 at about $0.03 / 1K tokens, and GPT-3.5 Turbo at about $0.002 / 1K tokens.
    • Non-English languages often use roughly 30%–50% more tokens because of encoding differences.
    • A custom prompt may increase the risk of translated text overlapping or duplicating the original text, especially in complex-layout or OCR scenarios.
  2. BabelDOC status
    • For 1.x, enabling BabelDOC is not recommended.
    • pdf2zh 2.0 was rewritten around BabelDOC and enables it by default with better compatibility.

Usage steps
#

1. GUI
#

Run the GUI, choose a model translation service, click Open for More Experimental Options!, paste the prompt into Custom Prompt for llm, and save.

2. Command line
#

Save the prompt as prompt.txt, then run pdf2zh example.pdf --prompt prompt.txt. Use an absolute path if necessary.

3. Zotero for pdf2zh
#

Download the latest server.py, find the cmd = [ ... ] list, and add a --prompt argument after the config path. Put prompt.txt in the same folder as server.py, or adjust the path.

BabelDOC
#

BabelDOC is an open-source PDF document translation tool with CLI and Python APIs. It uses layout-preservation techniques to keep original page structure, formulas, and figures during translation.

For current use, my preference is: keep BabelDOC off for 1.x and leave it alone for 2.0, because 2.0 enables it by default. BabelDOC often produces better layouts, but translated Chinese copied from PDFs can become ASCII-encoded and hard to search. If that happens, open the output in a different PDF reader. Large models may also output abnormal formats such as bolded terms or numbered variable fragments; a stronger model such as DeepSeek-V3 can reduce this.

Prompt
#

For pdf2zh 1.x, use the long academic-translation prompt below. For pdf2zh 2.x, the custom prompt is simpler: you mainly customize the role. Replace [academic research] with a specific field such as [biomedical engineering] or [quantitative finance] when you need domain-specific terminology.


Closing
#

PDFMathTranslate + custom prompts can be a powerful combination for PDF translation. I hope this helps you turn foreign-language PDFs into a readable native-language workflow while preserving the document itself. If you have questions, leave a comment and keep iterating the workflow together.

Screenshots and media
#

image.png
a4df2100fba3a2453247b3a70037dff3.png
b2a03c247081745745c426ef90e277a6.png
image.png

Preserved command, configuration, and prompt blocks
#

1
pdf2zh -i
1
pdf2zh example.pdf --prompt prompt.txt
1
pdf2zh example.pdf --prompt "C:\Users\YourName\Documents\prompt.txt"
1
'--prompt', './prompt.txt'
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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 路径(注意:\一定要换成/)
]
1
You are a world-class, expert-level machine translation engine designed for academic and technical translation from English to Simplified Chinese (zh-CN). You are an expert in [academic research].Your objective is to produce translations that meet the rigorous standards of top-tier peer-reviewed journals. You must achieve domain-expert level accuracy, faithfully and precisely reproducing the source text's nuances, tone, and complexity without any paraphrasing or omission. When translating, strictly follow the instructions below to ensure translation quality and preserve all formatting, tags, and placeholders:

Related tools

Related