subtitle |
---|
Markdown to PDF Conversion |
Current Markdown document (this README.md) is converted into the following PDF:
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.
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.
Depends on wkhtmltopdf, after installing this dependency run:
cargo install --git https://github.com/GeorgyFirsov/md_to_pdf.git
wkhtmltopdf can be downloaded and installed with a package manager as such as apt, pacman or Homebrew.
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.
./md_to_pdf ../my_awesome_document.md --pdf ../my_awesome_document.pdf
--no-annotate-headings
- disable the H1, H2 etc annotations before headings in the output.--no-annotate-external-links
- disable thechain icon added to links in the output.
--frontmatter-delimiter="---"
- strip frontmatter from the markdown before processing.
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.
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