hebrew-document-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Hebrew Document Generator

希伯来语文档生成器

Instructions

使用说明

Step 1: Choose the Output Format

步骤1:选择输出格式

FormatLibraryBest ForRTL Support
PDFreportlabInvoices, tax docs, printable formsRegister Hebrew font, use
canvas.drawRightString()
PDFWeasyPrintStyled documents from HTML/CSSNative via
dir="rtl"
in HTML
DOCXpython-docxContracts, proposals, meeting minutesSet paragraph
bidi
and RTL run properties
PPTXpptxgenjs (Node)Presentations, slide decksRTL text boxes with
rtlMode: true
格式适用场景RTL支持方式
PDFreportlab发票、税务文档、可打印表单注册希伯来语字体,使用
canvas.drawRightString()
PDFWeasyPrint基于HTML/CSS的样式化文档通过HTML中的
dir="rtl"
原生支持
DOCXpython-docx合同、报价单、会议纪要设置段落
bidi
和RTL运行属性
PPTXpptxgenjs (Node)演示文稿、幻灯片启用
rtlMode: true
的RTL文本框

Step 2: Install Dependencies and Hebrew Fonts

步骤2:安装依赖包和希伯来语字体

Python PDF generation:
bash
pip install reportlab weasyprint
Python DOCX generation:
bash
pip install python-docx python-bidi
Node.js PPTX generation:
bash
npm install pptxgenjs
Recommended Hebrew fonts (install on system):
FontStyleBest ForSource
HeeboSans-serif, modernWeb-style documents, invoicesGoogle Fonts
DavidClassic serifLegal contracts, formal lettersSystem (Windows/macOS)
NarkisimSerif, elegantProposals, invitationsSystem (Windows)
Frank RuehlTraditional serifAcademic, literaryGoogle Fonts (Frank Ruhl Libre)
RubikSans-serif, roundedPresentations, marketingGoogle Fonts
AssistantSans-serif, cleanBusiness correspondenceGoogle Fonts
See
references/hebrew-fonts.md
for download links and installation instructions.
Python PDF生成:
bash
pip install reportlab weasyprint
Python DOCX生成:
bash
pip install python-docx python-bidi
Node.js PPTX生成:
bash
npm install pptxgenjs
推荐希伯来语字体(需安装到系统):
字体样式适用场景来源
Heebo无衬线、现代风格网页风格文档、发票Google Fonts
David经典衬线法律合同、正式信函系统自带(Windows/macOS)
Narkisim衬线、优雅风格报价单、邀请函系统自带(Windows)
Frank Ruehl传统衬线学术、文学文档Google Fonts(Frank Ruhl Libre)
Rubik无衬线、圆角风格演示文稿、营销材料Google Fonts
Assistant无衬线、简洁风格商务信函Google Fonts
下载链接和安装说明请查看
references/hebrew-fonts.md

Step 3: Generate Hebrew PDF with reportlab

步骤3:使用reportlab生成希伯来语PDF

See
scripts/generate_doc.py
for the full generation pipeline.
python
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib.units import mm
from bidi import get_display  # python-bidi 0.6.x; see note below
完整生成流程请查看
scripts/generate_doc.py
python
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib.units import mm
from bidi import get_display  # python-bidi 0.6.x; see note below

Register Hebrew font

Register Hebrew font

pdfmetrics.registerFont(TTFont('Heebo', 'Heebo-Regular.ttf')) pdfmetrics.registerFont(TTFont('Heebo-Bold', 'Heebo-Bold.ttf'))
def create_hebrew_pdf(filename, title, content_lines): c = canvas.Canvas(filename, pagesize=A4) width, height = A4
# Title -- right-aligned for RTL
c.setFont('Heebo-Bold', 18)
hebrew_title = get_display(title)
c.drawRightString(width - 20*mm, height - 30*mm, hebrew_title)

# Body lines
c.setFont('Heebo', 12)
y = height - 50*mm
for line in content_lines:
    display_line = get_display(line)
    c.drawRightString(width - 20*mm, y, display_line)
    y -= 7*mm

c.save()

Key points for reportlab Hebrew:
- Always use `get_display()` from python-bidi to reorder characters
- Use `drawRightString()` for right-aligned RTL text
- Register TTF Hebrew fonts explicitly -- reportlab has no built-in Hebrew support
- Set line height to at least 1.5x font size for Hebrew readability
- **python-bidi import:** since python-bidi 0.5.0 the canonical import is `from bidi import get_display` (the old `from bidi.algorithm import get_display` path was removed). Current python-bidi is 0.6.x, which restored a parallel algorithm module but kept the top-level import as the recommended one. python-bidi 0.6.x also dropped support for Python below 3.9.
- **Multi-line text:** `drawRightString()` draws a single line and does NOT wrap. For any body text longer than one line, use reportlab's `Paragraph` flowable (from `reportlab.platypus`) with a right-aligned, RTL `ParagraphStyle` instead. The bundled `scripts/generate_doc.py` uses per-line `drawRightString` for compact fixed-layout documents (invoices, receipts); it will clip long Hebrew strings. Reach for `Paragraph` / platypus flowables for contracts or any wrapping body copy.
pdfmetrics.registerFont(TTFont('Heebo', 'Heebo-Regular.ttf')) pdfmetrics.registerFont(TTFont('Heebo-Bold', 'Heebo-Bold.ttf'))
def create_hebrew_pdf(filename, title, content_lines): c = canvas.Canvas(filename, pagesize=A4) width, height = A4
# Title -- right-aligned for RTL
c.setFont('Heebo-Bold', 18)
hebrew_title = get_display(title)
c.drawRightString(width - 20*mm, height - 30*mm, hebrew_title)

# Body lines
c.setFont('Heebo', 12)
y = height - 50*mm
for line in content_lines:
    display_line = get_display(line)
    c.drawRightString(width - 20*mm, y, display_line)
    y -= 7*mm

c.save()

reportlab生成希伯来语文档的关键点:
- 必须使用python-bidi的`get_display()`对字符重新排序
- 使用`drawRightString()`实现RTL文本右对齐
- 显式注册TTF希伯来语字体——reportlab无内置希伯来语支持
- 行高至少设置为字体大小的1.5倍以保证希伯来语可读性
- **python-bidi导入说明:** 自python-bidi 0.5.0起,标准导入方式为`from bidi import get_display`(旧路径`from bidi.algorithm import get_display`已移除)。当前python-bidi版本为0.6.x,恢复了algorithm模块的并行路径,但仍推荐使用顶层导入。python-bidi 0.6.x不再支持Python 3.9以下版本。
- **多行文本:** `drawRightString()`仅绘制单行文本,不支持自动换行。对于超过一行的正文内容,请使用reportlab的`Paragraph`流式组件(来自`reportlab.platypus`),并设置右对齐的RTL`ParagraphStyle`。附带的`scripts/generate_doc.py`使用逐行`drawRightString`生成紧凑的固定布局文档(如发票、收据);长希伯来语字符串会被截断。合同或需要自动换行的正文内容请使用`Paragraph`/platypus流式组件。

Mixed Hebrew / Latin / Digit Lines

希伯来语/拉丁语/数字混合行

The single most common RTL failure in generated documents is a line that mixes a Hebrew description with LTR numbers and a currency symbol, for example an invoice line item.
get_display()
handles the bidi reordering, but you must pass the whole logical string in one call so the algorithm sees the full context:
python
from bidi import get_display
生成文档中最常见的RTL问题是希伯来语描述与LTR数字、货币符号混合的行(如发票明细项)。
get_display()
可处理双向排序,但必须传入完整的逻辑字符串,以便算法获取完整上下文:
python
from bidi import get_display

Logical order: Hebrew description, then qty, unit price, currency

Logical order: Hebrew description, then qty, unit price, currency

line = 'ייעוץ טכני (3 שעות) - 1,500.00 ש"ח' c.setFont('Heebo', 11) c.drawRightString(width - 20 * mm, y, get_display(line))

The digits, the comma, the period, and the parentheses all stay in their correct LTR positions because the bidi algorithm resolves them relative to the surrounding Hebrew. Do NOT split the line into pieces and reorder them yourself, and do NOT call `get_display()` on the Hebrew part only, both approaches break the number ordering.
line = 'ייעוץ טכני (3 שעות) - 1,500.00 ש"ח' c.setFont('Heebo', 11) c.drawRightString(width - 20 * mm, y, get_display(line))

数字、逗号、句号和括号会保持正确的LTR位置,因为双向算法会根据周围的希伯来语内容自动解析。请勿自行拆分文本并重新排序,也请勿仅对希伯来语部分调用`get_display()`,这两种方式都会破坏数字顺序。

Step 4: Generate Hebrew PDF with WeasyPrint

步骤4:使用WeasyPrint生成希伯来语PDF

python
from weasyprint import HTML

html_content = """
<!DOCTYPE html>
<html lang="he" dir="rtl">
<head>
<meta charset="utf-8">
<style>
  @font-face {
    font-family: 'Heebo';
    src: url('Heebo-Regular.ttf');
  }
  body {
    font-family: 'Heebo', sans-serif;
    direction: rtl;
    font-size: 12pt;
    line-height: 1.7;
  }
  h1 { font-size: 18pt; text-align: start; }
  table {
    width: 100%;
    border-collapse: collapse;
  }
  th, td {
    border: 1px solid #333;
    padding: 6px 10px;
    text-align: start;
  }
</style>
</head>
<body>
  <h1>חשבונית מס</h1>
  <!-- Document content here -->
</body>
</html>
"""

HTML(string=html_content).write_pdf('invoice.pdf')
WeasyPrint advantages for Hebrew:
  • Full CSS support including logical properties
  • Native RTL via HTML
    dir
    attribute
  • Tables render correctly in RTL
  • Supports
    @font-face
    for custom Hebrew fonts
python
from weasyprint import HTML

html_content = """
<!DOCTYPE html>
<html lang="he" dir="rtl">
<head>
<meta charset="utf-8">
<style>
  @font-face {
    font-family: 'Heebo';
    src: url('Heebo-Regular.ttf');
  }
  body {
    font-family: 'Heebo', sans-serif;
    direction: rtl;
    font-size: 12pt;
    line-height: 1.7;
  }
  h1 { font-size: 18pt; text-align: start; }
  table {
    width: 100%;
    border-collapse: collapse;
  }
  th, td {
    border: 1px solid #333;
    padding: 6px 10px;
    text-align: start;
  }
</style>
</head>
<body>
  <h1>חשבונית מס</h1>
  <!-- Document content here -->
</body>
</html>
"""

HTML(string=html_content).write_pdf('invoice.pdf')
WeasyPrint处理希伯来语的优势:
  • 完整支持CSS逻辑属性
  • 通过HTML
    dir
    属性原生支持RTL
  • 表格可正确渲染RTL布局
  • 支持
    @font-face
    自定义希伯来语字体

Step 5: Generate Hebrew DOCX with python-docx

步骤5:使用python-docx生成希伯来语DOCX

python
from docx import Document
from docx.shared import Pt, Inches
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml.ns import qn

def set_paragraph_rtl(paragraph):
    """Set paragraph direction to RTL for Hebrew text."""
    pPr = paragraph._p.get_or_add_pPr()
    bidi = pPr.makeelement(qn('w:bidi'), {})
    pPr.append(bidi)
    paragraph.alignment = WD_ALIGN_PARAGRAPH.RIGHT

def set_run_rtl(run):
    """Set run direction to RTL."""
    rPr = run._r.get_or_add_rPr()
    rtl = rPr.makeelement(qn('w:rtl'), {})
    rPr.append(rtl)

doc = Document()
python
from docx import Document
from docx.shared import Pt, Inches
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml.ns import qn

def set_paragraph_rtl(paragraph):
    """Set paragraph direction to RTL for Hebrew text."""
    pPr = paragraph._p.get_or_add_pPr()
    bidi = pPr.makeelement(qn('w:bidi'), {})
    pPr.append(bidi)
    paragraph.alignment = WD_ALIGN_PARAGRAPH.RIGHT

def set_run_rtl(run):
    """Set run direction to RTL."""
    rPr = run._r.get_or_add_rPr()
    rtl = rPr.makeelement(qn('w:rtl'), {})
    rPr.append(rtl)

doc = Document()

Set default font

Set default font

style = doc.styles['Normal'] font = style.font font.name = 'David' font.size = Pt(12)
style = doc.styles['Normal'] font = style.font font.name = 'David' font.size = Pt(12)

Add Hebrew heading

Add Hebrew heading

heading = doc.add_heading(level=1) run = heading.add_run('חוזה שירותים') set_run_rtl(run) set_paragraph_rtl(heading)
heading = doc.add_heading(level=1) run = heading.add_run('חוזה שירותים') set_run_rtl(run) set_paragraph_rtl(heading)

Add Hebrew paragraph

Add Hebrew paragraph

para = doc.add_paragraph() run = para.add_run('הסכם זה נערך ונחתם ביום...') run.font.name = 'David' run.font.size = Pt(12) set_run_rtl(run) set_paragraph_rtl(para)
doc.save('contract.docx')
undefined
para = doc.add_paragraph() run = para.add_run('הסכם זה נערך ונחתם ביום...') run.font.name = 'David' run.font.size = Pt(12) set_run_rtl(run) set_paragraph_rtl(para)
doc.save('contract.docx')
undefined

Step 6: Generate Hebrew PPTX with pptxgenjs

步骤6:使用pptxgenjs生成希伯来语PPTX

javascript
const pptxgen = require('pptxgenjs');
const pptx = new pptxgen();

pptx.layout = 'LAYOUT_16x9';
pptx.rtlMode = true;

const slide = pptx.addSlide();

// Hebrew title
slide.addText('סקירה רבעונית', {
  x: 0.5, y: 0.5, w: '90%', h: 1.0,
  fontSize: 28,
  fontFace: 'Heebo',
  color: '1a1a2e',
  align: 'right',
  rtlMode: true,
  bold: true,
});

// Hebrew bullet points
slide.addText([
  { text: 'תוצאות כספיות', options: { bullet: true, rtlMode: true } },
  { text: 'יעדים לרבעון הבא', options: { bullet: true, rtlMode: true } },
  { text: 'סיכום פעילות', options: { bullet: true, rtlMode: true } },
], {
  x: 0.5, y: 2.0, w: '90%', h: 3.0,
  fontSize: 18,
  fontFace: 'Heebo',
  align: 'right',
  rtlMode: true,
});

pptx.writeFile({ fileName: 'quarterly-review.pptx' });
javascript
const pptxgen = require('pptxgenjs');
const pptx = new pptxgen();

pptx.layout = 'LAYOUT_16x9';
pptx.rtlMode = true;

const slide = pptx.addSlide();

// Hebrew title
slide.addText('סקירה רבעונית', {
  x: 0.5, y: 0.5, w: '90%', h: 1.0,
  fontSize: 28,
  fontFace: 'Heebo',
  color: '1a1a2e',
  align: 'right',
  rtlMode: true,
  bold: true,
});

// Hebrew bullet points
slide.addText([
  { text: 'תוצאות כספיות', options: { bullet: true, rtlMode: true } },
  { text: 'יעדים לרבעון הבא', options: { bullet: true, rtlMode: true } },
  { text: 'סיכום פעילות', options: { bullet: true, rtlMode: true } },
], {
  x: 0.5, y: 2.0, w: '90%', h: 3.0,
  fontSize: 18,
  fontFace: 'Heebo',
  align: 'right',
  rtlMode: true,
});

pptx.writeFile({ fileName: 'quarterly-review.pptx' });

Step 7: Israeli Business Document Templates

步骤7:以色列商务文档模板

See
references/templates.md
for complete field specifications per document type.
TemplateHebrew NameRequired Fields
Tax Invoiceחשבונית מסBusiness name, Osek Murshe number, date, line items, VAT (18%), total
ContractחוזהParties, TZ/company numbers, terms, signatures, date
Price Proposalהצעת מחירBusiness details, itemized pricing, validity period, terms
Meeting MinutesפרוטוקולDate, attendees, agenda, decisions, action items
ReceiptקבלהBusiness name, receipt number, amount, payment method, date
Tax Invoice (Heshbonit Mas) required fields by Israeli law:
  • Business name and address
  • Osek Murshe (authorized dealer) number
  • Sequential invoice number
  • Date of issue
  • Customer name and TZ/company number
  • Line items with description, quantity, unit price
  • Subtotal, VAT at 18%, and total in NIS
各类文档的完整字段规范请查看
references/templates.md
模板希伯来语名称必填字段
税务发票חשבונית מס企业名称、Osek Murshe编号、日期、明细项、增值税(18%)、总计
合同חוזה双方信息、身份证/企业编号、条款、签名、日期
报价单הצעת מחיר企业详情、分项定价、有效期、条款
会议纪要פרוטוקול日期、参会人员、议程、决议、行动项
收据קבלה企业名称、收据编号、金额、支付方式、日期
以色列法律规定的税务发票(Heshbonit Mas)必填字段:
  • 企业名称和地址
  • Osek Murshe(授权经销商)编号
  • 连续发票编号
  • 开具日期
  • 客户名称和身份证/企业编号
  • 含描述、数量、单价的明细项
  • 小计、18%增值税、新以色列谢克尔(NIS)总计

Examples

示例

Example 1: Generate Tax Invoice PDF

示例1:生成税务发票PDF

User says: "Create a Hebrew tax invoice PDF for my business" Result: Use reportlab or WeasyPrint to generate A4 PDF with RTL layout, business header, sequential invoice number, itemized table, VAT calculation at 18%, totals in NIS with shekel symbol, and Hebrew font throughout.
用户需求:“为我的企业创建希伯来语税务发票PDF” 结果:使用reportlab或WeasyPrint生成A4尺寸的PDF,包含RTL布局、企业页眉、连续发票编号、分项表格、18%增值税计算、带谢克尔符号的NIS总计,全程使用希伯来语字体。

Example 2: Create Hebrew Contract DOCX

示例2:创建希伯来语合同DOCX

User says: "Draft a Hebrew service contract as a Word document" Result: Use python-docx with bidi paragraph support, David font, RTL alignment, structured sections (parties, scope, payment terms, termination, signatures), proper Hebrew legal phrasing.
用户需求:“起草一份希伯来语服务合同Word文档” 结果:使用支持双向段落的python-docx,采用David字体、RTL对齐,包含结构化章节(双方信息、服务范围、付款条款、终止条款、签名),使用标准希伯来语法律措辞。

Example 3: Build Hebrew Presentation

示例3:制作希伯来语演示文稿

User says: "Make a Hebrew PowerPoint for our quarterly review" Result: Use pptxgenjs with rtlMode enabled, Heebo font, right-aligned text boxes, RTL bullet points, Hebrew slide titles, and professional layout.
用户需求:“为我们的季度评审制作希伯来语PowerPoint” 结果:使用启用rtlMode的pptxgenjs,采用Heebo字体、右对齐文本框、RTL项目符号、希伯来语幻灯片标题,搭配专业布局。

Example 4: Batch Document Generation

示例4:批量生成文档

User says: "Generate 50 Hebrew invoices from a CSV file" Result: Read CSV data, iterate rows, use
scripts/generate_doc.py
to produce individual PDFs with unique invoice numbers, customer details, and line items per row.
用户需求:“从CSV文件生成50份希伯来语发票” 结果:读取CSV数据,遍历每一行,使用
scripts/generate_doc.py
生成包含唯一发票编号、客户详情和对应明细项的独立PDF。

Bundled Resources

附带资源

Scripts

脚本

  • scripts/generate_doc.py
    - Generate Hebrew PDF documents with reportlab: register Hebrew fonts, apply RTL text reordering with python-bidi, produce Israeli business documents (invoices, receipts) with proper VAT calculations and NIS formatting. Run:
    python scripts/generate_doc.py --help
  • scripts/generate_doc.py
    - 使用reportlab生成希伯来语PDF文档:注册希伯来语字体,通过python-bidi实现RTL文本重排序,生成符合要求的以色列商务文档(发票、收据),包含正确的增值税计算和NIS格式。运行方式:
    python scripts/generate_doc.py --help

References

参考文档

  • references/hebrew-fonts.md
    - Hebrew font catalog with recommended fonts for different document types (sans-serif, serif, monospace), Google Fonts download links, system font availability matrix, font pairing suggestions, and installation instructions for macOS, Linux, and Windows.
  • references/templates.md
    - Israeli business document templates with required fields per document type (tax invoice, contract, proposal, receipt, meeting minutes), Israeli legal requirements for invoices, VAT rules, and standard Hebrew business phrasing.
  • references/hebrew-fonts.md
    - 希伯来语字体目录,包含不同文档类型推荐字体(无衬线、衬线等)、Google Fonts下载链接、系统字体可用性矩阵、字体搭配建议,以及macOS、Linux、Windows系统的安装说明。
  • references/templates.md
    - 以色列商务文档模板,包含各类文档(税务发票、合同、报价单、收据、会议纪要)的必填字段、以色列发票法律要求、增值税规则和标准希伯来语商务措辞。

Reference Links

参考链接

SourceURLWhat to Check
reportlab documentationhttps://docs.reportlab.com/Canvas API, platypus flowables, font registration
WeasyPrint documentationhttps://doc.courtbouillon.org/weasyprint/stable/HTML/CSS to PDF, RTL support, @font-face
python-docx documentationhttps://python-docx.readthedocs.io/Document model, runs, paragraph properties
python-bidi (PyPI)https://pypi.org/project/python-bidi/Current version, import path, changelog
Israeli tax invoice requirementshttps://he.wikipedia.org/wiki/%D7%97%D7%A9%D7%91%D7%95%D7%A0%D7%99%D7%AA_%D7%9E%D7%A1Mandatory fields for a Heshbonit Mas; cross-check against current Israel Tax Authority rules
For binding legal requirements always confirm against the current Israel Tax Authority (Rashut HaMisim) guidance, the Wikipedia entry is a starting orientation, not the authority.
来源URL查看内容
reportlab文档https://docs.reportlab.com/Canvas API、platypus流式组件、字体注册
WeasyPrint文档https://doc.courtbouillon.org/weasyprint/stable/HTML/CSS转PDF、RTL支持、@font-face
python-docx文档https://python-docx.readthedocs.io/文档模型、运行属性、段落属性
python-bidi(PyPI)https://pypi.org/project/python-bidi/当前版本、导入路径、更新日志
以色列税务发票要求https://he.wikipedia.org/wiki/%D7%97%D7%A9%D7%91%D7%95%D7%A0%D7%99%D7%AA_%D7%9E%D7%A1Heshbonit Mas必填字段;请与以色列税务局现行规则交叉验证
法律相关要求请始终以以色列税务局(Rashut HaMisim)的最新指南为准,维基百科条目仅作为入门参考,不具备权威效力。

Recommended MCP Servers

推荐MCP服务器

No MCP server applies to this skill. Hebrew document generation runs entirely through local Python and Node libraries (reportlab, WeasyPrint, python-docx, pptxgenjs); there is no external service to wrap as an MCP server. Use the bundled scripts and the code in the Instructions section directly.
本技能无需MCP服务器。希伯来语文档生成完全通过本地Python和Node库(reportlab、WeasyPrint、python-docx、pptxgenjs)实现;无需封装外部服务为MCP服务器。直接使用附带脚本和使用说明中的代码即可。

Gotchas

注意事项

  • get_display()
    must be applied per line at draw time, immediately before
    drawRightString()
    , NOT once on a whole multi-line document or block. The bidi algorithm is not idempotent: running it on text that was already reordered double-reverses the characters and produces scrambled output. A common agent mistake is to "pre-process" a whole list of lines through
    get_display()
    and then call it again inside the draw loop.
  • PDF generators often default to left-to-right text flow. Hebrew documents MUST use RTL paragraph direction, and mixed Hebrew-English text requires proper BiDi (bidirectional) algorithm support.
  • Agents may pick fonts that lack Hebrew character support (e.g., Arial works, but many decorative Latin fonts do not). Always verify the font includes the Hebrew Unicode range (U+0590-U+05FF).
  • Hebrew date formatting uses DD/MM/YYYY in secular context and Hebrew calendar dates (e.g., 15 Adar 5786) for religious/traditional documents. Agents may default to MM/DD/YYYY.
  • Legal documents in Israel require specific formatting: nikud (vowel marks) is NOT used in standard business/legal Hebrew. Agents may add nikud thinking it improves clarity, but it actually looks unprofessional in formal documents.
  • get_display()
    必须在绘制时逐行调用,即紧接在
    drawRightString()
    之前,而非对整个多行文档或文本块一次性预处理。双向算法不具备幂等性:对已排序的文本再次调用会导致字符反向两次,产生乱码。常见错误是提前将所有行通过
    get_display()
    预处理,然后在绘制循环中再次调用。
  • PDF生成器通常默认左到右文本流。希伯来语文档必须使用RTL段落方向,希伯来语-英语混合文本需要正确的双向(BiDi)算法支持。
  • 可能会选择不支持希伯来语字符的字体(如Arial可用,但许多装饰性拉丁语字体不可用)。请始终验证字体包含希伯来语Unicode范围(U+0590-U+05FF)。
  • 希伯来语日期格式在世俗场景中使用DD/MM/YYYY,宗教/传统文档使用希伯来日历日期(如15 Adar 5786)。默认可能会使用MM/DD/YYYY格式。
  • 以色列法律文档有特定格式要求:标准商务/法律希伯来语不使用nikud(元音标记)。若添加nikud可能会被认为是不专业的做法,而非提升清晰度。

Troubleshooting

故障排除

Error: "Hebrew characters display as boxes or question marks"

错误:“希伯来语字符显示为方框或问号”

Cause: Hebrew font not registered or not found on system Solution: Download a Hebrew TTF font (e.g., Heebo from Google Fonts), register it with
pdfmetrics.registerFont()
for reportlab, or install it as a system font for WeasyPrint.
原因:希伯来语字体未注册或系统中未找到 解决方案:下载希伯来语TTF字体(如Google Fonts的Heebo),在reportlab中使用
pdfmetrics.registerFont()
注册,或为WeasyPrint安装为系统字体。

Error: "Text appears left-to-right instead of right-to-left"

错误:“文本显示为左到右而非右到左”

Cause: Missing bidi reordering or RTL direction setting Solution: For reportlab, apply
get_display()
from python-bidi. For python-docx, call
set_paragraph_rtl()
and
set_run_rtl()
. For WeasyPrint, ensure
dir="rtl"
on the HTML element.
原因:缺少双向排序或RTL方向设置 解决方案:reportlab需应用python-bidi的
get_display()
;python-docx需调用
set_paragraph_rtl()
set_run_rtl()
;WeasyPrint需确保HTML元素设置
dir="rtl"

Error: "Numbers and punctuation in wrong position"

错误:“数字和标点位置错误”

Cause: Bidirectional text algorithm not handling mixed Hebrew/number content Solution: Wrap numeric sequences in LTR marks. In reportlab, use
get_display()
with
base_dir='R'
. In HTML-based tools, ensure proper
unicode-bidi: isolate
on embedded LTR spans.
原因:双向文本算法未处理希伯来语/数字混合内容 解决方案:将数字序列包裹在LTR标记中。reportlab中使用
get_display()
并设置
base_dir='R'
;基于HTML的工具需确保嵌入的LTR span设置
unicode-bidi: isolate