oparaskos / md_to_pdf

Simple utility to convert from markdown format into pretty PDF document. It is written in Rust programming language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

subtitle
Markdown to PDF Conversion

md_to_pdf

Example

Current Markdown document (this README.md) is converted into the following PDF: Example


Brief

Simple utility to convert from Markdown format into pretty PDF document. It is written in Rust programming language using several libraries:

  • comrak to convert markdown into HTML,
  • wkhtmltopdf to parse HTML with embedded CSS and render PDF document.

How it works

This small console app converts Markdown text directly into HTML document, which is extended and decorated by CSS styles. Full CSS style is embedded into the application as a resource and then inserted into the HTML document. After that application parses some HTML tokens and extends them by adding custom classes to them. This HTML document is converted into PDF file.

Installing

Depends on wkhtmltopdf, after installing this dependency run:

cargo install --git https://github.com/GeorgyFirsov/md_to_pdf.git

Linux and MacOS

wkhtmltopdf can be downloaded and installed with a package manager as such as apt, pacman or Homebrew.

Windows

A windows installer for wkhtmltopdf is available from the downloads page. Note that you may need to configure your environment in such a way that your linker can find the .DLL and .LIB files in their installation directory.

Usage

./md_to_pdf ../my_awesome_document.md --pdf ../my_awesome_document.pdf

Feature Flags

  • --no-annotate-headings - disable the H1, H2 etc annotations before headings in the output.
  • --no-annotate-external-links - disable the đź”— chain icon added to links in the output.
  • --frontmatter-delimiter="---" - strip frontmatter from the markdown before processing.

Custom templates and styles

see example.sh

  • --master-template="example_template/document.html.hbs" override the default master template with a custom one (enables custo cover pages)
  • --additional-stylesheets="example_template/styles.css" add to the base stylesheet with one or more additional stylesheets.

Using another HTML->PDF engine

wkhtmltopdf is marked as deprecated, in the case of report generation or where HTML input can be trusted, they recommend using an alternative such as weasyprint, prince, etc.

For this reason you can omit the --pdf option which will stop the program generating a PDF file, and instead use the --html option, which will output the generated HTML.

md_to_pdf --html out.html README.md
weasyprint .\out.html out.pdf

About

Simple utility to convert from markdown format into pretty PDF document. It is written in Rust programming language.

License:GNU General Public License v3.0


Languages

Language:Rust 82.3%Language:CSS 13.7%Language:Handlebars 2.9%Language:Shell 1.1%