Skip to main content

gospelo-md2pdf

Convert Markdown to PDF with Japanese support and MermaidJS diagrams.

Features

  • Japanese Text Support: Full support for Japanese fonts (Noto Sans CJK JP, Hiragino Sans, Yu Gothic)
  • MermaidJS Diagrams: Automatically renders Mermaid diagrams as PNG images via Kroki API
  • Image Embedding: Automatically embeds local and remote images as Base64 data URIs for portable PDFs
  • Custom CSS: Use your own stylesheets or the built-in professional style
  • Markdown Extensions: Tables, fenced code blocks, TOC, metadata, and more
  • Special HTML Classes: Summary boxes, warnings, pros/cons sections, page breaks
  • Agent Skills: Built-in support for AI coding assistants (Claude Code, Web Claude, VS Code Copilot)

Installation

pip install gospelo-md2pdf

System Dependencies

WeasyPrint requires system libraries. Install them first:

macOS:

brew install pango glib gdk-pixbuf libffi

Ubuntu/Debian:

sudo apt install libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0

Japanese Fonts (Recommended)

For Japanese text rendering:

macOS:

brew install font-noto-sans-cjk-jp

Ubuntu/Debian:

sudo apt install fonts-noto-cjk

MermaidJS Support

Mermaid diagrams are rendered using the Kroki API (no local installation required). Supported Mermaid version depends on Kroki's implementation (currently Mermaid v11.x).

For Web Claude: Add kroki.io to allowed domains:

  1. Settings (gear icon) → Capabilities
  2. Find "Additional allowed domains"
  3. Add kroki.io

Quick Start

# Basic usage
gospelo-md2pdf report.md

# Specify output file
gospelo-md2pdf report.md output.pdf

# Specify output directory
gospelo-md2pdf report.md -o ./pdf

# Use custom CSS
gospelo-md2pdf report.md --css custom-style.css

# Keep intermediate files for debugging
gospelo-md2pdf report.md --debug

Usage

gospelo-md2pdf <input.md> [output.pdf] [options]

Arguments:
  input.md              Input Markdown file
  output.pdf            Output PDF file (optional)

Options:
  -o, --output-dir DIR  Output directory (default: current directory)
  -c, --css FILE        Custom CSS file
  --debug               Keep intermediate files (HTML, mermaid) in tmp/ directory
  --lang LANG           HTML lang attribute (default: ja)
  -q, --quiet           Suppress output messages
  --verbose             Print verbose output
  -v, --version         Show version
  -h, --help            Show help

Environment Variables

Variable Description Default
MD2PDF_OUTPUT_DIR Output directory Current directory

Note: --output-dir option takes precedence over the environment variable.

Markdown Features

Basic Syntax

# Heading 1
## Heading 2
### Heading 3

Paragraph with **bold** and *italic* text.

- Bullet list
- Another item
  - Nested item

1. Numbered list
2. Another item

> Blockquote

`inline code`

[Link](https://example.com)

Tables

| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
| A        | B        | C        |
| D        | E        | F        |

Code Blocks

```python
def hello():
    print("Hello, World!")
```

MermaidJS Diagrams

```mermaid
graph TD
    A[Start] --> B[Process]
    B --> C{Decision}
    C -->|Yes| D[Result A]
    C -->|No| E[Result B]
```

Supported diagram types:

  • Flowcharts (graph TD, graph LR)
  • Sequence diagrams (sequenceDiagram)
  • Class diagrams (classDiagram)
  • State diagrams (stateDiagram-v2)
  • ER diagrams (erDiagram)
  • And all other Mermaid diagram types

Note: Tall diagrams are automatically scaled to fit within a single page (max-height: 700px) while preserving aspect ratio.

Images

Images in Markdown are automatically embedded as Base64 data URIs:

![Local image](./images/photo.png)
![Remote image](https://example.com/image.png)

Supported sources:

  • Relative paths: ./images/photo.png (resolved from Markdown file location)
  • Absolute paths: /home/user/image.png
  • HTTP/HTTPS URLs: Remote images are fetched and embedded

This ensures PDFs are fully portable with no external dependencies.

Special HTML Classes

Use these HTML classes in your Markdown for special styling:

Summary Box (Green)

<div class="summary">
Important summary points here.
</div>

Warning Box (Orange)

<div class="warning">
Warning message here.
</div>

Info Box (Blue)

<div class="info">
Additional information here.
</div>

Pros/Cons

<div class="pros">
Pros: High scalability
</div>

<div class="cons">
Cons: Initial cost
</div>

Disclaimer

<div class="disclaimer">
This report is for informational purposes only.
</div>

Page Break

<div class="page-break"></div>

Python API

from gospelo_md2pdf import convert_md_to_pdf

# Basic usage
convert_md_to_pdf("report.md")

# With options
convert_md_to_pdf(
    input_file="report.md",
    output_file="output.pdf",
    output_dir="./pdf",
    css_file="custom.css",
    keep_html=True,
    lang="ja",
    verbose=True
)

Troubleshooting

Japanese text not rendering

Check if Japanese fonts are installed:

fc-list :lang=ja | head -5

WeasyPrint library errors on macOS

Set the library path:

export DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH

Add to ~/.zshrc for persistence:

echo 'export DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH' >> ~/.zshrc
source ~/.zshrc

Mermaid diagrams not rendering

  1. Verify network connectivity to kroki.io
  2. For Web Claude: Add kroki.io to allowed domains (Settings → Capabilities → Additional allowed domains)
  3. Check error messages for "Cannot connect to Kroki"

Requirements

  • Python >= 3.10
  • weasyprint >= 60.0
  • markdown >= 3.5.0
  • System: pango, glib, gdk-pixbuf (see Installation)
  • Network: Access to kroki.io (for Mermaid diagrams)

Dependencies and Acknowledgements

This project uses the following open-source libraries. Full license texts are included in the LICENSE file.

Library License Description
WeasyPrint BSD 3-Clause HTML/CSS to PDF converter
Python-Markdown BSD 3-Clause Markdown to HTML converter
Kroki MIT Diagram rendering API

System Libraries (Dynamically Linked)

Library License Description
Pango LGPL 2.0+ Text rendering
GLib LGPL 2.1+ Core utilities
GDK-Pixbuf LGPL 2.1+ Image loading

Note: System libraries are dynamically linked and not bundled with this package.

Fonts (Recommended)

Font License Description
Noto Sans CJK JP OFL 1.1 Japanese font by Google

Note: Fonts are not bundled with this package. Users install them separately.

License

MIT License - see LICENSE for details.

Author

NoStudio LLC (goro-hayakawa@no-studio.net)

Documentation

Links

Metadata

Release files for gospelo-md2pdf 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gospelo-md2pdf 1.3.0
File Size Uploaded Provenance Actions
gospelo_md2pdf-1.3.0.tar.gz 24.9 kB Without provenance Details for gospelo_md2pdf-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gospelo-md2pdf 1.3.0
File Interpreter ABI Platform Actions
gospelo_md2pdf-1.3.0-py3-none-any.whl Python 3 none any Details for gospelo_md2pdf-1.3.0-py3-none-any.whl

Total release size: 43.3 kB

Release files / gospelo_md2pdf-1.3.0.tar.gz

Download URL gospelo_md2pdf-1.3.0.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7b451bcdb124a80c23f0bb4bbc7d472295fd0f8384488a7e78b2d8094e3a2105
BLAKE2b-256 checksum
How to use checksums
a4c01b77462a4c2846bd84925165f7b07fd469e1f822c6503ab4e487bae3adec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release files / gospelo_md2pdf-1.3.0-py3-none-any.whl

Download URL gospelo_md2pdf-1.3.0-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3fcec252f62cf512e500530271c7c712f441b3d7e59e876692f061712297bd30
BLAKE2b-256 checksum
How to use checksums
9e079ac68eb7205e421679da82952c85200ea0a8cc45e8230b5aa7e6cd8acb13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Security for gospelo-md2pdf 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page