🌟 A Rust-Based CLI Tool to Convert Markdown Files to PDF with Customizable Formatting and Templates 🌟
- Introduction
- Features
- System Requirements
- Installation
- Getting Started
- Usage
- Contributing
- Security
- Code of Conduct
- Support
- License
- Acknowledgements
vox-md is an open-source command-line interface (CLI) tool written in Rust that converts Markdown files to professionally formatted PDF documents. Leveraging the pulldown-cmark
library for Markdown parsing and wkhtmltopdf
for PDF generation, it offers customizable templates, page sizes, margins, font sizes, and orientations. Designed for developers, writers, and documentation enthusiasts, vox-md simplifies the process of creating polished PDFs from Markdown with minimal setup.
The tool supports three built-in HTML templates (default
, modern
, minimal
) for styling, and users can create custom templates for further personalization. With verbose logging and robust error handling, vox-md ensures a reliable and user-friendly experience.
Note: This project is actively maintained. It requires
wkhtmltopdf
to be installed on your system. Contributions to add new features, templates, or improve performance are welcome!
- Markdown to PDF Conversion:
- Parses Markdown files using
pulldown-cmark
and converts them to HTML. - Generates PDFs using
wkhtmltopdf
with high-quality rendering.
- Parses Markdown files using
- Customizable Output:
- Supports multiple page sizes: A4, Letter, Legal.
- Configurable margins (in millimeters).
- Portrait or landscape orientation.
- Custom document title and base font size.
- Template System:
- Includes three built-in templates:
default
,modern
,minimal
. - Allows custom HTML templates stored in the
templates/
directory. - Templates support dynamic font size substitution.
- Includes three built-in templates:
- Command-Line Interface:
- Built with
structopt
for intuitive argument parsing. - Supports flags for input/output paths, template selection, and verbose logging.
- Built with
- Error Handling:
- Validates input (
.md
extension) and output (.pdf
extension) files. - Provides clear error messages for missing files, invalid templates, or configuration issues.
- Validates input (
- Verbose Mode:
- Detailed logs for debugging (e.g., template loading, PDF generation steps).
- Cross-Platform:
- Runs on Windows, macOS, and Linux with
wkhtmltopdf
installed.
- Runs on Windows, macOS, and Linux with
- Lightweight:
- Minimal dependencies and efficient Rust implementation.
To run vox-md, ensure you have:
- Operating System: Windows, macOS, or Linux.
- Rust: Stable toolchain (version 1.56 or higher recommended).
- wkhtmltopdf: Installed and accessible in your system PATH.
- Install via package manager:
- Ubuntu/Debian:
sudo apt-get install wkhtmltopdf
- macOS:
brew install wkhtmltopdf
- Windows: Download from wkhtmltopdf.org
- Ubuntu/Debian:
- Install via package manager:
- Disk Space: ~10 MB for the compiled binary, templates, and dependencies (output PDFs vary by content).
- Dependencies (managed by Cargo):
pulldown-cmark
: Markdown parsing.wkhtmltopdf
: PDF generation.structopt
: CLI argument parsing.
- Input Files:
- Markdown files with
.md
extension. - Optional: Custom HTML templates in the
templates/
directory.
- Markdown files with
Follow these steps to install and set up vox-md:
-
Install Rust:
- Install the Rust toolchain via rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Update Rust:
rustup update
- Install the Rust toolchain via rustup:
-
Install wkhtmltopdf:
- Linux (Ubuntu/Debian):
sudo apt-get update sudo apt-get install wkhtmltopdf
- macOS:
brew install wkhtmltopdf
- Windows: Download and install from wkhtmltopdf.org, then add to PATH.
- Linux (Ubuntu/Debian):
-
Clone the Repository:
git clone https://github.com/VoxDroid/vox-md.git
-
Navigate to the Project Directory:
cd vox-md
-
Build the Project:
cargo build --release
The compiled binary will be located at
target/release/vox-md
. -
(Optional) Install Globally:
- Copy the binary to a directory in your PATH (e.g.,
/usr/local/bin
on Linux/macOS):sudo cp target/release/vox-md /usr/local/bin/
- Copy the binary to a directory in your PATH (e.g.,
-
Verify Installation:
vox-md --help
This should display the CLI help message with available options.
-
Prepare Templates:
- Ensure the
templates/
directory containsdefault.html
,modern.html
, andminimal.html
. - Example template structure:
<!DOCTYPE html> <html> <head> <style> body { font-size: {{FONT_SIZE}}pt; } </style> </head> <body> {{CONTENT}} </body> </html>
- Ensure the
Note: If
wkhtmltopdf
is not in your PATH, you may need to specify its location via environment variables or update your system configuration.
To start using vox-md:
-
Prepare a Markdown File:
- Create a sample Markdown file (e.g.,
sample.md
):# My Document This is a **sample** Markdown file. - Item 1 - Item 2
- Create a sample Markdown file (e.g.,
-
Run vox-md:
- Convert
sample.md
tooutput.pdf
using the default template:vox-md sample.md
- Specify a custom output path and template:
vox-md sample.md -o mydoc.pdf --template modern --page-size Letter
- Convert
-
Explore Options:
- Use verbose mode for detailed logs:
vox-md sample.md -v
- Customize margins and font size:
vox-md sample.md --margin 20 --font-size 14
- Set landscape orientation and title:
vox-md sample.md --orientation landscape --title "My Custom Document"
- Use verbose mode for detailed logs:
-
Verify Output:
- Open the generated PDF (e.g.,
output.pdf
) in a PDF viewer. - Check formatting, template styling, and content accuracy.
- Open the generated PDF (e.g.,
Convert a Markdown file to PDF with default settings:
vox-md input.md
- Input:
input.md
- Output:
output.pdf
- Template:
default
- Page Size: A4
- Margin: 12mm
- Orientation: Portrait
- Font Size: 12pt
- Title: "Markdown Document"
Use flags to customize the PDF:
vox-md input.md -o custom.pdf --template minimal --page-size Legal --margin 15 --orientation landscape --font-size 10 --title "Project Report"
-o
: Specify output file.--template
: Choosedefault
,modern
, orminimal
(or custom template name).--page-size
: Set to A4, Letter, or Legal.--margin
: Set margin in millimeters.--orientation
: Set to portrait or landscape.--font-size
: Set base font size in points.--title
: Set PDF document title.
Enable detailed logging for debugging:
vox-md input.md -v
Output includes template loading, HTML conversion, and PDF generation steps.
- Create a new HTML template in
templates/
(e.g.,custom.html
):<!DOCTYPE html> <html> <head> <style> body { font-size: {{FONT_SIZE}}pt; font-family: Arial; } h1 { color: navy; } </style> </head> <body> {{CONTENT}} </body> </html>
- Use the custom template:
vox-md input.md --template custom
- Write a Markdown file (
report.md
):# Annual Report ## Summary This report covers **2025** performance. - Revenue: $1M - Growth: 10%
- Generate a PDF with the modern template:
vox-md report.md -o report.pdf --template modern --page-size Letter --margin 10
- Open
report.pdf
to view the styled document.
To try vox-md:
- Clone the repository and install dependencies as described in Installation.
- Create a sample Markdown file (e.g.,
sample.md
). - Run:
vox-md sample.md -o sample.pdf --template minimal
- Open
sample.pdf
to view the result.
We welcome contributions to vox-md! To get involved:
- Review the Contributing Guidelines for details on submitting issues, feature requests, or pull requests.
- Fork the repository, make changes, and submit a pull request.
- Adhere to the Code of Conduct to ensure a respectful community.
Example contributions:
- Add new templates or styling options.
- Support additional Markdown features (e.g., tables, code blocks).
- Improve error messages or add new CLI flags.
- Optimize PDF generation performance.
Security is a priority for vox-md. If you discover a vulnerability:
- Report it privately as outlined in the Security Policy.
- Avoid public disclosure until the issue is resolved.
All contributors and users are expected to follow the Code of Conduct to maintain a welcoming and inclusive environment.
Need help with vox-md? Visit the Support page for resources, including:
- Filing bug reports or feature requests.
- Community discussions and contact information.
- FAQs for common issues (e.g., wkhtmltopdf setup, template errors).
vox-md is licensed under the MIT License. See the LICENSE file for details.
- VoxDroid: For creating and maintaining the project.
- Rust Community: For providing robust libraries like
pulldown-cmark
andwkhtmltopdf
. - wkhtmltopdf: For reliable PDF generation.
- Contributors: Thanks to all who report issues, suggest features, or contribute code.
- Markdown Users: For inspiring tools that simplify documentation workflows.