Skip to content

855princekumar/md2pdf

Repository files navigation

3-banner

Type Language Output Rendering Diagrams Assets Mode Platform Architecture Workflow Distribution StatusDownload

md2pdf

md2pdf is an offline, isolated Markdown to PDF and DOCX conversion toolkit designed for fast, reliable documentation workflows with full support for Mermaid diagrams, SVG assets, and batch processing.

It was built to remove dependency on online tools and token-based AI conversions, and to provide a deterministic, local, and reproducible documentation pipeline.


Download and Run (60-Second Setup)

 Download md2pdf for Windows

No installation required. Fully offline.

Extract → Run md2pdf.exe → Convert


Quick Start

  1. Download and extract the ZIP

You will see:

md2pdf.exe
md2pdf.ico
ms-playwright/
  1. Run:
<!-- -->
md2pdf.exe
  1. Select your Markdown file

Done.


Output

Generated in same folder:

PDF/
DOCX/

Important

Do NOT delete:

ms-playwright/

No installation required. Fully offline.


Linux release coming soon.


Background and Motivation

Markdown has become my primary format for documentation because of its speed, simplicity, and compatibility with tools like:

For rendering and exporting, I previously relied on online tools such as:

These worked well until I encountered a real-world constraint while traveling: the services were unavailable when I needed to deliver documentation urgently.

This exposed several limitations:

  • Dependence on internet connectivity
  • Service downtime risk
  • Lack of batch automation
  • No isolated, reproducible environment
  • Wasted time and compute tokens for simple format conversion

This led to building a fully offline solution.

The goal was simple:

A fast, reliable, offline Markdown conversion tool that produces:

  • publication-quality PDF
  • editable DOCX
  • full Mermaid support
  • full SVG support
  • batch conversion capability
  • isolated bootstrap environment

This project is the result of that effort.


Design Philosophy

md2pdf follows these principles:

  • Offline-first
  • Deterministic output
  • Fully isolated runtime
  • No global dependency pollution
  • Bootstrap-and-run architecture
  • Minimal user friction
  • Reproducible documentation pipeline

Each script version creates its own virtual environment and runs within it automatically.

No manual activation required.


Evolution and Iterations

The project evolved through four major iterations.

Each iteration was an MVP designed to validate a specific part of the pipeline.


Version 1 - Basic Markdown to PDF

Initial proof-of-concept.

Single file conversion using local rendering.

Workflow:

flowchart LR
    A[Markdown File] --> B[Convert to HTML]
    B --> C[Render via Chromium]
    C --> D[Export PDF]
Loading

Limitations:

  • Single file only
  • No Mermaid support
  • No SVG support
  • No DOCX

Version 2 - GitHub-Quality Rendering

Added GitHub-style rendering and Mermaid support.

Workflow:

flowchart LR
    A[Markdown] --> B[HTML Conversion]
    B --> C[Inject GitHub CSS]
    C --> D[Inject Mermaid Engine]
    D --> E[Chromium Render]
    E --> F[PDF Export]
Loading

Improvements:

  • GitHub-style output
  • Mermaid rendering
  • SVG rendering

Limitations:

  • Single file conversion
  • No DOCX export

Version 3 - Batch Conversion Pipeline

Added multi-file selection and batch processing.

Workflow:

flowchart LR
    A[Multiple Markdown Files] --> B[Loop Through Files]
    B --> C[Render HTML]
    C --> D[Chromium Render]
    D --> E[Export PDF]
Loading

Improvements:

  • Batch conversion
  • Stable rendering

Limitations:

  • No editable format output

Version 4 - Final Pipeline (Current Release)

Full production workflow.

Supports:

  • Batch conversion
  • PDF export
  • Editable DOCX export
  • Mermaid rendering
  • SVG rendering
  • Asset support
  • Isolated bootstrap

Final Architecture

Complete workflow:

flowchart TD

    A[Markdown Files]

    A --> B[Bootstrap Virtual Environment]

    B --> C[Convert Markdown to HTML]

    C --> D[Inject GitHub CSS]

    D --> E[Inject Mermaid Engine]

    E --> F[Render using Chromium]

    F --> G[Export PDF]

    F --> H[Extract Rendered Elements]

    H --> I[Convert Mermaid to PNG]

    H --> J[Convert SVG to PNG]

    H --> K[Extract Editable Text]

    I --> L[Build DOCX]

    J --> L

    K --> L

    L --> M[Output DOCX]

Loading

Output Structure

For a Markdown file:

project/
    README.md

Output:

project/
    PDF/
        README.pdf

    DOCX/
        README.docx

DOCX Output Behavior

Text remains editable.

Mermaid diagrams are inserted as images.

SVG diagrams are inserted as images.

Layout remains clean and usable.


SVG Asset Path Recommendation (GitHub-Style Rendering)

For best compatibility and predictable rendering, it is recommended to store SVG files inside an assets folder located in the same directory as the Markdown file.

Recommended structure:

project/

    README.md

    assets/

        architecture.svg
        flow.svg

Reference inside Markdown:

![Architecture](assets/architecture.svg)

This approach follows the same rendering strategy used by GitHub README rendering.

Benefits:

  • consistent rendering across GitHub, VS Code, and md2pdf
  • no broken image paths
  • fast local rendering
  • clean project organization
  • easier portability and sharing

This design decision was inspired directly by GitHub’s README rendering flow, ensuring the exported PDF and DOCX match the same visual output seen in repository documentation.


Installation

Clone repository:

git clone https://github.com/855princekumar/md2pdf.git

cd md2pdf

Run:

python md-to-pdf-docx.py

The script will:

  • create isolated environment
  • install dependencies
  • launch conversion tool

No setup required.


Supported Features

Markdown features:

  • headings
  • tables
  • code blocks
  • lists
  • images

Diagram support:

  • Mermaid
  • SVG

Output formats:

  • PDF
  • DOCX

Processing modes:

  • single file
  • batch conversion

Platforms:

  • Windows
  • Linux

Development Philosophy

Each script in this repository represents a tested stage of the pipeline.

These versions are preserved intentionally to provide:

  • architectural reference
  • experimentation base
  • customization starting point

Users can modify or extend any stage.


Use Case

Typical workflow:

Write documentation in:

  • Obsidian
  • VS Code
  • ChatGPT
  • Gemini

Preview locally.

Run md2pdf.

Export:

  • distribution-ready PDF
  • editable DOCX for team collaboration

Why This Exists

This tool exists to eliminate:

  • dependency on online converters
  • downtime risks
  • token-based conversion waste
  • formatting inconsistencies
  • manual conversion overhead

It acts as a local documentation Swiss-army knife.


Repository Structure

md2pdf/

    md-to-pdf-docx.py
    version-history/
    examples/
    README.md

Actual Repository Folder Structure (Development Evolution)

The repository also contains the full architectural evolution history:

md2pdf/

├── 1-beta-version/
│     └── md-to-pdf.py
│
├── 2-half-render-version/
│     └── md-to-pdf.py
│
├── 3-full-render-version/
│     └── md-to-pdf.py
│
├── 4-DOC+PDF-full-render/
│     └── md-to-pdf.py
│
└── README.md

Final production version:

4-DOC+PDF-full-render

This contains the complete rendering pipeline.


VS Code Integration Workflow

Primary documentation workflow uses:

VS Code Markdown Preview Enhanced:

https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced

This extension allows:

  • live preview
  • Mermaid rendering
  • project-folder documentation workflow

Typical workflow:

Write Markdown
        ↓
Preview in VS Code Extension
        ↓
Convert using md2pdf
        ↓
Share PDF or DOCX

This ensures:

  • consistent rendering
  • fast export
  • offline reliability
  • team-friendly sharing

Team members can either:

  • use the extension

or

  • use exported PDF / DOCX

Standalone Executable Builds (EXE and TAR)

Standalone builds are also provided for direct use.

No Python installation required.

Available:

Windows:

md2pdf.exe

Linux:

md2pdf.tar.gz

Workflow:

Launch Tool
    ↓
Select Markdown File
    ↓
Click Convert
    ↓
PDF and DOCX Generated

Output:

PDF/
DOCX/

This makes it ideal for:

  • engineering teams
  • offline systems
  • production documentation
  • non-technical users

Future Improvements

Planned:

  • executable build
  • drag-and-drop interface
  • folder watch mode
  • CI integration
  • CLI arguments

License

MIT License


Closing Note

md2pdf was built out of necessity during real-world constraints.

It has since become part of my daily documentation workflow.

Using VS Code with Markdown Preview Enhanced and exporting via md2pdf has created a complete offline documentation pipeline.

If you work heavily with Markdown, especially with diagrams and structured documentation, this tool is designed to make your pipeline faster, reproducible, and independent.


About

Offline Markdown → PDF & DOCX converter | Mermaid, SVG, batch support | GitHub-style rendering

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages