Skip to content

v0.8.1

Latest

Choose a tag to compare

@github-actions github-actions released this 30 Nov 11:40
· 2 commits to main since this release

BabelDOC v0.8.1

Highlights

  • BabelDOC 0.8.1 is the first PyPI and GitHub Release of the 0.8 series (the v0.8.0 tag was skipped on PyPI after an Intel macOS Python 3.14 CI packaging check failed). It requires Python 3.11–3.14 on Linux, Windows, and Apple Silicon macOS; Intel macOS remains supported on Python 3.11–3.13 because upstream onnxruntime no longer provides Intel macOS wheels for Python 3.14. Release builds target Linux x86-64 and ARM64 (manylinux_2_28), Windows x86-64, macOS Intel, and macOS Apple Silicon with one abi3 wheel per platform for standard CPython. Building from source requires a Rust toolchain and compatible dependencies.
    BabelDOC 0.8.1 是 0.8 系列首个发布到 PyPI 和 GitHub Release 的正式版本(v0.8.0 tag 因 Intel Mac 上的 Python 3.14 CI 打包冒烟失败而跳过发布)。本版本在 Linux、Windows 和 Apple 芯片 Mac 上支持 Python 3.11–3.14;Intel Mac 因上游 onnxruntime 不再提供 Python 3.14 的 Intel Mac 预编译包,仍支持 Python 3.11–3.13。发布流程面向 Linux x86-64 和 ARM64(manylinux_2_28)、Windows x86-64、Intel Mac 和 Apple 芯片 Mac 构建,每个平台各一个面向标准 CPython 的 abi3 wheel。源码构建需要 Rust 工具链和兼容的依赖。
  • Reworked PDF output to preserve graphics more reliably. Saving no longer runs PyMuPDF's content cleanup on generated page streams, avoiding known cases of missing text or damaged graphics involving inline images, color operators, Type 3 glyphs, and special font names. The writer also handles shared forms and PDF name escaping more reliably and preserves the graphics state needed when a form and its image both use soft masks.
    改进了 PDF 输出的图形保真度。保存生成页面时跳过 PyMuPDF 的内容流清理,避免在处理内联图像、颜色算子、Type 3 字形或特殊字体名时发生已知的丢字或图形损坏。写出时也改进了共享表单和 PDF 名称转义处理,并保留表单和其中的图像同时使用软遮罩时所需的图形状态。
  • The writer uses Flate compression where it reduces the size of rebuilt streams and removes page font and XObject resources it can verify are unused. When translating in parts, the final merge now respects skip_clean=True and skips font subsetting.
    写出时会用 Flate 压缩能缩小体积的重建内容流,并移除能确认未被引用的页级字体和 XObject。分片翻译时,最终合并现在遵守 skip_clean=True 并跳过字体子集化。
  • BabelDOC now detects image-only scans using PDF structure and classifies OCR text by paragraph on candidate pages. Searchable scans with usable text can be translated. For translated passages over scanned backgrounds, BabelDOC can match the mask to the sampled background (adaptive_ocr_mask=True) and use white text on dark backgrounds. It also filters verified occluded text (remove_occluded_text=True) and redundant invisible text from translation.
    BabelDOC 现在根据 PDF 结构检测纯图扫描件,并在候选页按段落识别 OCR 文字。含可用文字层的可搜索扫描件可以翻译。对于扫描背景上的已翻译段落,BabelDOC 可根据采样背景色调整遮盖颜色(adaptive_ocr_mask=True),并在深色背景上使用白字。翻译时也会过滤经验证被覆盖的底层文本(remove_occluded_text=True)及冗余的不可见文字。
  • New Computer Modern body fonts no longer trigger the default math-font rule. Formula bars, such as fraction bars and radical bars, stay with their formulas when BabelDOC can match them geometrically.
    New Computer Modern 正文字体不再触发默认数学字体规则。BabelDOC 可依据位置将分数线、根号横线等细线与对应公式一起保留。
  • Typesetting now applies its font scaling limit even without progress reporting. If the translated text cannot fit, BabelDOC falls back to the original paragraph. It also avoids shrinking a paragraph's bounding box merely because a neighboring box touches it horizontally.
    即使关闭进度报告,排版仍会应用字号缩放上限。如果译文无法排入,BabelDOC 会回退保留原段落。横向相邻且边缘接触的段落也不会因此挤小文字框。
  • BabelDOC preserves the original paragraph when a reply leaves the text unchanged after normalization or contains no translated text. It also handles literal placeholders and stray JSON control characters in translation replies more reliably.
    翻译响应归一化后与原文相同,或未提供有效译文时,BabelDOC 会保留原段落。BabelDOC 也改进了对字面占位符和翻译响应中意外 JSON 控制字符的处理。
  • Automatic glossary extraction preserves user entries and prefers them when the same source term is found. A glossary match is skipped if an ASCII letter or digit at either edge of the term touches another ASCII letter or digit in the text.
    自动提取术语时会保留用户词条。同一源词同时出现在用户词表和自动提取结果时,优先使用用户词条。只要术语任一边缘的 ASCII 字母或数字紧邻正文中的另一 ASCII 字母或数字,该处就不会匹配。
  • Fixed cases where copied text contained unexpected characters, including CJK compatibility forms. Generated font mappings now favor the characters actually written, and the CMap post-processing recognizes subset font names and skips mappings it cannot parse.
    修复了复制生成 PDF 的文字时出现非预期字符的部分情况,包括部分中日韩兼容字符。生成的字体映射优先采用实际写入的字符。CMap 后处理可以识别字体子集名称,并跳过无法解析的映射。
  • Fixed bookmark destinations in side-by-side bilingual PDFs that include only the selected pages. BabelDOC also closes PDF files explicitly after post-processing, delivers async_translate() finish and error events after the translation worker has cleaned up, and supports capture_stages=True on standard wheels (issue #644).
    修复了仅保留所选页面的并排双语 PDF 书签跳转位置。BabelDOC 也会在后处理时显式关闭 PDF 文件,在翻译 worker 完成清理后才发出 async_translate() 的完成或错误事件,并在标准 wheel 上直接支持 capture_stages=True(见 issue #644)。

Dependency Updates

  • Default installations no longer require pyzstd, rtree, huggingface-hub, Levenshtein, or uharfbuzz. BabelDOC now installs plain xsdata by default, and pymupdf remains constrained to >=1.26.7,<2.
    默认安装不再依赖 pyzstd、rtree、huggingface-hub、Levenshtein 和 uharfbuzz。BabelDOC 默认安装不带附加依赖组的 xsdata,pymupdf 约束仍保持 >=1.26.7,<2。
  • The cuda and memray installation extras were removed (memray is now a development dependency on non-Windows platforms). If your environment needs onnxruntime-gpu or memray, declare it explicitly. The directml extra remains available.
    安装选项 cuda 和 memray 已移除(memray 现仅在非 Windows 平台作为开发依赖)。环境如需 onnxruntime-gpu 或 memray,请显式声明依赖。directml 安装选项保持保留。

Compatibility Notes

  • Python 3.10 dropped; Linux Python 3.14 forkserver: Python 3.10 is no longer supported. On Linux, Python 3.14 defaults to forkserver for multiprocessing; in standalone scripts, put the code that calls translate() under if __name__ == "__main__": so the worker can import the main module safely.
    Python 3.10 停止支持;Linux Python 3.14 默认使用 forkserver:不再支持 Python 3.10。Linux 上的 Python 3.14 默认使用 forkserver 启动子进程;在独立脚本中,请将调用 translate() 的入口代码放在 if __name__ == "__main__": 保护内,使子进程可以安全导入主模块。
  • Unified tri-state ocr_mode: use TranslationConfig(ocr_mode="auto") to detect OCR text automatically, "on" to force OCR handling (skipping scan rejection and disabling rich-text translation), or "off" to skip scan rejection and disable OCR masking. OCR modes use existing text layers. In automatic mode, BabelDOC can raise ScannedPDFError if at least 80% of the selected pages in the scan check are classified as scans with no usable text (pages with only small footer text can count toward that decision); when translating in parts, the scan check is limited to one part.
    统一三态 ocr_mode:使用 TranslationConfig(ocr_mode="auto") 自动识别 OCR 文字,用 "on" 强制按 OCR 处理(跳过扫描件拒绝检查并关闭富文本翻译),用 "off" 跳过扫描件拒绝检查并关闭 OCR 遮盖。OCR 模式依赖已有文字层。自动模式下,纳入扫描检查的所选页面若至少有 80% 被判为缺少可用文字的扫描页,BabelDOC 可能抛出 ScannedPDFError(仅有少量页脚小字的扫描页也可能计入);分片翻译时,扫描检查限于一个分片。
  • Legacy OCR flag migration: if ocr_mode is omitted, the first enabled legacy flag wins — ocr_workaround selects "on", followed by auto_enable_ocr_workaround for "auto" and skip_scanned_detection for "off", and with none enabled the mode defaults to "auto". Setting both ocr_workaround=True and auto_enable_ocr_workaround=True now selects "on". Explicit ocr_mode="auto" with skip_scanned_detection=True skips front-gate scan rejection while keeping automatic paragraph classification.
    旧 OCR 参数迁移:省略 ocr_mode 时按顺序采用第一个开启的旧参数——ocr_workaround 对应 "on",其次 auto_enable_ocr_workaround 对应 "auto",最后 skip_scanned_detection 对应 "off",三者均未开启时默认落入 "auto"。同时开启 ocr_workaround=True 与 auto_enable_ocr_workaround=True 时现在会直接进入 "on"。显式传入 ocr_mode="auto" 并设 skip_scanned_detection=True 时会跳过前置扫描拒绝检查,同时保留段落级自动 OCR 分类。
  • Public API signatures: existing calls to translate() and async_translate() can use the same arguments. TranslationConfig keeps its existing parameters and adds optional ocr_mode, remove_occluded_text, and adaptive_ocr_mask settings.
    公开 API 签名:现有 translate() 和 async_translate() 调用可继续使用原有参数。TranslationConfig 保留既有参数,并新增可选的 ocr_mode、remove_occluded_text 与 adaptive_ocr_mask 配置项。

Contributors & Acknowledgements

Because BabelDOC develops in a private repository and syncs releases to this public repository, community PRs and patches are often ported or adapted rather than merged directly on GitHub. Many thanks to everyone who contributed code, patches, diagnoses, and detailed bug reports to v0.8.1:
由于 BabelDOC 在私有仓库开发并向公开仓库同步发布,社区提交的 PR 与补丁通常会经过移植或适配而非直接在 GitHub 合并。非常感谢以下朋友为 v0.8.1 贡献代码、补丁、问题定位与详尽反馈:

Code, Patches & Proofs of Concept

  • @BlackSharkJ (#604, #597): deep ToUnicode CMap root-cause analysis and four-part fix for CJK compatibility codepoints (#278), plus identifying unclosed PyMuPDF Document handles causing Windows file locks.
    @BlackSharkJ(#604、#597):深入定位 ToUnicode CMap 问题并给出四项 CJK 兼容码位核心修复(#278),同时定位了未关闭 PyMuPDF Document 句柄导致 Windows 文件锁的问题。
  • @dmitrigauss (#645): detailed root-cause analysis and flat_curve_formula_score patch for claiming zero-height fraction and radical bars into formulas.
    @dmitrigauss(#645):给出详尽根因分析与 flat_curve_formula_score 补丁,解决零高度分数线与根号横线未被公式认领而残留的问题。
  • @ice917 (#637, #635): is_standalone_match ASCII alphanumeric word-boundary matcher and boundary tests, plus the user-glossary-first union design when automatic term extraction is enabled.
    @ice917(#637、#635):贡献 is_standalone_match ASCII 词边界匹配实现与完整边界测试,并提出自动提取术语时「用户词表优先合并」的设计方案。
  • @pentaoa (#622): narrowing the built-in precise formula-font patterns to NewCMMath and NewComputerModernMath along with a thorough test checklist (#613).
    @pentaoa(#622):将内置精确数学字体正则收窄至 NewCMMath 与 NewComputerModernMath 并附完整测试清单,解决 New Computer Modern 正文被误判为公式的问题(#613)。
  • @BetterAndBetterII (#612): pinpointing C0 control-character JSON parsing failures in LLM responses and contributing the review discussion that shaped the context-aware Rust JSON sanitizer (#577).
    @BetterAndBetterII(#612):定位 LLM 响应中 C0 控制字符引发的 JSON 解析失败,其测试与 review 讨论直接促成了 Rust 端字符串上下文感知清洗器的设计(#577)。
  • @hazugi2004 (#611, #610): catching the unreachable unchanged-translation check and highlighting the need for bilateral excessive-punctuation normalization before comparing.
    @hazugi2004(#611、#610):抓出同文译文分支类型错配的死代码问题,并点出比较前需要对输入与输出双边做连续标点归一化。
  • @qazxcdswe123 (#641): same-direction proof of concept, integration tests, and code-block reproduction for preserving original paragraph layout when translation is unchanged (#610).
    @qazxcdswe123(#641):为 #610 提交了同向概念验证、多路径集成测试与代码块排版对比复现。
  • @FaintFlower (#607): fixing the broken README Star History chart links (star-history.dera.page).
    @FaintFlower(#607):修复 README 中失效的 Star History 图表链接(迁移至 star-history.dera.page)。

Bug Reports & Reproductions

  • @clariantb (#624): tracing how BaseTranslator's plain-string default placeholder getters caused b/B and / characters to be stripped from translations.
    @clariantb(#624):精准排查出 BaseTranslator 默认纯字符串占位符模板导致译文中 b/B 与 / 被误删的根因。
  • @wujunxiao1 (#613) & @zavior: reporting and confirming the New Computer Modern body-text formula misclassification on real Typst/academic PDFs.
    @wujunxiao1(#613)与 @zavior:在真实 Typst / 学术论文 PDF 上反馈并交叉验证了 New Computer Modern 正文被误判为公式的问题。
  • @UCPRER (#278): reporting copied Chinese text garbling in Zotero caused by non-canonical CJK compatibility codepoints.
    @UCPRER(#278):反馈译文 PDF 导入 Zotero 后复制中文出现乱码的问题,推动了本次 ToUnicode CMap 与字体写出源头修复。
  • @Solomon-0827 (#644): feedback on 0.7.x observability that led to enabling stage-capture by default in published wheels and cleaning up leftover mod *_tests; declarations (#636).
    @Solomon-0827(#644):对 0.7.x 管线可观测性的反馈直接促成标准 wheel 默认开启 stage-capture,并一并清理了遗留的 mod *_tests; 声明(#636)。
  • @boyingliu01 (#569, #577): reporting and diagnosing control-character JSON parsing failures during translation.
    @boyingliu01(#569、#577):反馈并分析翻译过程中 PDF 控制字符引发 JSON 解析失败的问题。
  • @nghebanhcom-alt (#615) & @Hemir95 (#620): detailed reports and controlled experiments on silent blanking and dropped paragraphs that helped drive the empty-response and NoFit original-paragraph fallbacks.
    @nghebanhcom-alt(#615)与 @Hemir95(#620):关于空响应抹白与段落静默消失的详尽反馈与受控实验,推动了本版空响应与无法排入时的原段落回退保护。