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:
- Pandoc converts Markdown to standalone HTML with a table of contents.
md2pdf/style.csshandles CJK fonts, the cover page, TOC, headings, blockquotes, tables, and page breaks.- Playwright / headless Chrome prints the HTML to an A4 PDF.
- PyMuPDF + Pillow render QA images and a
summary.txtto check page count, page size, garbled (replacement) characters, and spot-check pages.
The PyPI distribution name is
md2pdf-tool(the plainmd2pdfname was already taken on PyPI). The installed command is stillmd2pdf.
Install
# Homebrew (personal tap) — pulls in pandoc automatically
brew install ethanzhrepo/md2pdf/md2pdf
# or pipx (install pandoc separately: brew install pandoc / apt install pandoc)
pipx install md2pdf-tool
md2pdf --version confirms what you got.
Two system dependencies cannot be installed by pip:
- pandoc — required. The Homebrew formula depends on it; with pipx, install it yourself.
- A headless browser — usually already covered. md2pdf launches an installed Google
Chrome if it can find one, and only falls back to Playwright's bundled Chromium. Run
playwright install chromium(a ~350 MB download) only if a run fails to launch a browser.
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 .
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.
Local image paths are resolved relative to the Markdown source file and embedded in the generated HTML before printing. Large images are scaled down to fit the printable page area while retaining their aspect ratio; smaller images keep their natural size.
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 --cover-label "需求说明书" docs/requirements.md
./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" \
--cover-label "需求说明书" \
--date "2026-06-03" \
--required-text "Final one-line goal"
--cover-label prints a small badge above the cover title. It is omitted by
default, so covers show only the title and date unless you ask for one.
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 bypip 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file md2pdf_tool-0.1.4.tar.gz.
File metadata
- Download URL: md2pdf_tool-0.1.4.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dccfcdebe4221f5d45292c7cbf5eacdae308c3a9f78fc7e5e53bfa3b7c8d4fc
|
|
| MD5 |
2933033f99bc556ca62632986fa67b2a
|
|
| BLAKE2b-256 |
fdc63d8043de561d2b884ca5a4ef73a788e9fbb6ae0d0e428733dc8afb35e470
|
Provenance
The following attestation bundles were made for md2pdf_tool-0.1.4.tar.gz:
Publisher:
release.yml on ethanzhrepo/md2pdf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2pdf_tool-0.1.4.tar.gz -
Subject digest:
4dccfcdebe4221f5d45292c7cbf5eacdae308c3a9f78fc7e5e53bfa3b7c8d4fc - Sigstore transparency entry: 2169423768
- Sigstore integration time:
-
Permalink:
ethanzhrepo/md2pdf@bc1cea8b1133ee9d780c719914a624038afbe3a5 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/ethanzhrepo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bc1cea8b1133ee9d780c719914a624038afbe3a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file md2pdf_tool-0.1.4-py3-none-any.whl.
File metadata
- Download URL: md2pdf_tool-0.1.4-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf22ea1543fe87cfa7b2de99c7c3933a779b6200334fb3f996c319da596c7e03
|
|
| MD5 |
eb3993cf1e50491c06c5fa47c74f2fd7
|
|
| BLAKE2b-256 |
9109d1eb180928440a371a8a2974cd7633ed343b4506c1cff66abdcf06531973
|
Provenance
The following attestation bundles were made for md2pdf_tool-0.1.4-py3-none-any.whl:
Publisher:
release.yml on ethanzhrepo/md2pdf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2pdf_tool-0.1.4-py3-none-any.whl -
Subject digest:
cf22ea1543fe87cfa7b2de99c7c3933a779b6200334fb3f996c319da596c7e03 - Sigstore transparency entry: 2169423849
- Sigstore integration time:
-
Permalink:
ethanzhrepo/md2pdf@bc1cea8b1133ee9d780c719914a624038afbe3a5 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/ethanzhrepo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bc1cea8b1133ee9d780c719914a624038afbe3a5 -
Trigger Event:
push
-
Statement type: