Skip to main content

Convert Markdown to a styled, Chinese-friendly A4 PDF with QA previews.

Project description

md2pdf

A Markdown-to-PDF tool tuned for Chinese / CJK documents:

  1. Pandoc converts Markdown to standalone HTML with a table of contents.
  2. md2pdf/style.css handles CJK fonts, the cover page, TOC, headings, blockquotes, tables, and page breaks.
  3. Playwright / headless Chrome prints the HTML to an A4 PDF.
  4. PyMuPDF + Pillow render QA images and a summary.txt to check page count, page size, garbled (replacement) characters, and spot-check pages.

The PyPI distribution name is md2pdf-tool (the plain md2pdf name was already taken on PyPI). The installed command is still md2pdf.

Install

Two system dependencies must be installed first (pip cannot install them):

  • pandocbrew install pandoc (macOS) / apt install pandoc (Debian/Ubuntu).
  • A headless browser — after installing the Python package, run playwright install chromium to download Playwright's bundled Chromium. On macOS an existing Google Chrome is reused automatically.

Then install the tool. For end users:

# Homebrew (personal tap)
brew install ethanzhrepo/md2pdf/md2pdf
playwright install chromium

# or pipx
pipx install md2pdf-tool
playwright install chromium

From source / for development:

pipx install .          # install from the repo, gives a global `md2pdf` command
# or an editable install:
python -m venv .venv && source .venv/bin/activate
pip install -e .
playwright install chromium

Usage

After installing, use the md2pdf command:

md2pdf docs/requirements.md

Without --output, the PDF is written next to the source with a .pdf suffix. Without --title, the filename stem is used.

There is also a gen_pdf.sh wrapper that reads the first level-1 Markdown heading as the cover title:

./gen_pdf.sh docs/requirements.md docs/requirements.pdf
./gen_pdf.sh --dry-run docs/requirements.md   # print the command without running it

To set the title, subtitle, date, or required text explicitly, pass the matching flags:

md2pdf docs/requirements.md \
  --output docs/requirements.pdf \
  --title "项目需求说明" \
  --subtitle "Private-deployment authoring, publishing, and playback platform" \
  --date "2026-06-03" \
  --required-text "Final one-line goal"

Without installing, you can also run it as a module from the repo root (requires pip install -e . or PYTHONPATH=src):

python -m md2pdf.build_pdf path/to/input.md --output path/to/output.pdf

Output

A run produces (using requirements as an example):

  • PDF: docs/requirements.pdf
  • Intermediate HTML: <build-dir>/requirements.html
  • QA summary: <build-dir>/qa/summary.txt
  • Spot-check page images and thumbnails: <build-dir>/qa/*.png

<build-dir> defaults to .build/<stem>/ next to the output PDF (user-writable, never written into a read-only install location). Use --build-dir to point it elsewhere, e.g. --build-dir ./.md2pdf-build.

Dependencies

  • pandoc
  • Python packages: playwright, PyMuPDF (fitz), Pillow (installed automatically by pip install)
  • Google Chrome or Playwright Chromium

Pandoc may print Could not load translations for zh-CN; this is harmless and does not affect Chinese content or PDF text extraction.

Tests

pip install -e .
python -m unittest discover -s tests -v

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

md2pdf_tool-0.1.2.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

md2pdf_tool-0.1.2-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file md2pdf_tool-0.1.2.tar.gz.

File metadata

  • Download URL: md2pdf_tool-0.1.2.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for md2pdf_tool-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2307906974073195876e79f3207ef237c4bc015115c97858ae7de9a600f51847
MD5 0ee59a5212062c62394b3c505953f40b
BLAKE2b-256 41307d740821f65d40193a92242c0024172c73c14c60b65d29f634b791d1429d

See more details on using hashes here.

Provenance

The following attestation bundles were made for md2pdf_tool-0.1.2.tar.gz:

Publisher: release.yml on ethanzhrepo/md2pdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file md2pdf_tool-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: md2pdf_tool-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for md2pdf_tool-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 61ecd69c4d244c8df9d8bc7ff7809c5ef25223f74e9c91c3965988f3cff403bc
MD5 3fdc295d12f563f0c559af9f150736d1
BLAKE2b-256 79956ad401f492c8d174f3be5811e50a63d89a59c5cecdacd1187346edaad4df

See more details on using hashes here.

Provenance

The following attestation bundles were made for md2pdf_tool-0.1.2-py3-none-any.whl:

Publisher: release.yml on ethanzhrepo/md2pdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page