ConvertX icon indicating copy to clipboard operation
ConvertX copied to clipboard

Add Chinese Font Support for Pandoc

Open ivanzhangwb opened this issue 2 months ago • 2 comments

Summary Added optional Chinese font support for the Pandoc converter, enabling proper rendering of Chinese characters in Markdown to PDF conversions.

Changes

Environment Variables (src/helpers/env.ts)

  • PANDOC_ENABLE_CHINESE_FONT: Enable/disable Chinese font support
  • PANDOC_CHINESE_FONT_PATH: Path to Chinese font files
  • PANDOC_CHINESE_FONT_FAMILY: Chinese font family name (default: SimSun)

Pandoc Converter Enhancement (src/converters/pandoc.ts)

  • Automatically detects and applies Chinese font configuration when converting to PDF/LaTeX formats
  • Adds Chinese font parameters when using XeLaTeX engine
  • Supports custom font paths and font families

Docker Configuration Example (compose.yaml)

  • Added Chinese font-related environment variable examples
  • Provided font file mounting configuration template

Usage

  1. Enable Chinese font support: 1 environment: 2 - PANDOC_ENABLE_CHINESE_FONT=true 3 - PANDOC_CHINESE_FONT_FAMILY=NotoSansCJK

  2. Mount host font files: 1 volumes: 2 - /usr/share/fonts/truetype/chinese:/usr/share/fonts/truetype/chinese:ro

Testing Recommendations Test the following scenarios:

  • Chinese Markdown to PDF conversion
  • Rendering effects of different Chinese fonts
  • Correctness of environment variable configuration
  • Test source file: markdown TestChinese.md and pdf TestChinese.pdf

This improvement enhances ConvertX's friendliness for Chinese users while maintaining code simplicity and maintainability.


Summary by cubic

Added optional Chinese font support for Pandoc PDF/LaTeX conversions so Chinese text renders correctly. Controlled via environment variables and disabled by default.

  • New Features

    • Pandoc adds XeLaTeX font settings when enabled.
    • Env vars: PANDOC_ENABLE_CHINESE_FONT, PANDOC_CHINESE_FONT_PATH, PANDOC_CHINESE_FONT_FAMILY (default: SimSun).
    • Dockerfile installs common Chinese font packages, initializes font cache, and sets zh_CN.UTF-8 locale; compose examples show font volume mount and env usage.
  • Migration

    • Set PANDOC_ENABLE_CHINESE_FONT=true.
    • Optionally set PANDOC_CHINESE_FONT_FAMILY and PANDOC_CHINESE_FONT_PATH.
    • Mount host fonts into the container if needed (read-only).

Written for commit 498a35b6f8cd0e451e4eafa7d85a0fec1ee6e755. Summary will update automatically on new commits.

ivanzhangwb avatar Dec 14 '25 15:12 ivanzhangwb

Nice! Is it possible to configure it in any way so that it automatically uses a CJK font when needed, so not everyone have to configure it? I think that would be extremely nice, but no worries if not :)

C4illin avatar Dec 14 '25 19:12 C4illin

Nice! Is it possible to configure it in any way so that it automatically uses a CJK font when needed, so not everyone have to configure it? I think that would be extremely nice, but no worries if not :)

Thanks for the feedback! Auto-switching for CJK fonts would be very convenient. Currently, it still needs to be manually enabled, as I haven't yet implemented reliable detection for CJK content in source files. 😅 . I'll keep this in mind for future improvements.

ivanzhangwb avatar Dec 15 '25 08:12 ivanzhangwb