Skip to content
Jeremiah Dodds edited this page Mar 30, 2011 · 4 revisions

Tutorial

So, all mkd2pdf is is a wrapper for a couple of programs -- a markdown-to-html converter, and a html-to-pdf converter. Let's say you have a little markdown file that you want to convert to pdf:

Some Guy

email   : [email protected]

phone   : 940-203-4093


A Headline
=============
+ A listitem
 **[A link](http://google.com)**
 A description
 + A sublistitem
 **[Another link](http://google.com)**
 Some more stuff
 - Designed and implemented a set of tools for automation of pr
 
Another Headline
===================

yup indeedy 

Prerequesites

First off, make sure there's a binary called markdown in your $PATH:

$ which markdown
/usr/bin/markdown

If you don't have a markdown parser, install one. If you have one and it has a different binary name, you can either do something like:

$ ln -s $(which mymarkdown) /usr/bin/markdown

or call mkd2pdf like so:

$ mkd2pdf -m mymarkdown inputfile.md

Now that we know we have a markdown parser, ensure that wkhtml2pdf is installed. You probably want to check your distro's package manager, and install that if they have one.

Passing in a stylesheet

Assuming we're good to go, let's take a look at what we can do here. Any styling that you want to do can be done if you make a stylesheet and pass it to mkd2pdf like so:

$ mkd2pdf -c /path/to/stylesheet inputfile.md

At the moment, this should be an absolute path.

Knowing what to style

But how do we know what to style? Well, we know that the end-result is going to be html, and that we can style this html with a stylesheet passed in. the canonical documentation for markdown is good, but if you want to take a quick glance at what you have to work with, just use markdown outside of the context of mkd2pdf:

$ markdown example.md
<p>Some Guy</p>
<p>email   : [email protected]</p>
<p>phone   : 940-203-4093</p>
<h1>A Headline</h1>
<ul>
<li>A listitem
 <strong><a href="http://google.com">A link</a></strong>
 A description</li>
<li>Another listitem
 <strong><a href="http://google.com">Another link</a></strong>
 Some more stuff</li>
<li>Designed and implemented a set of tools for automation of pr</li>
</ul>
<h1>Another Headline</h1>
<p>yup indeedy </p>

A simple stylesheet:

Well, that's pretty simple, so let's do a little styling:

body {
  background-color: black;
  color: white;
}

li {
  color: red;
}

running:

$ mkd2pdf -c /path/to/simple-style.css example.md simple-style.pdf

Will give us this file

Insert linebreaks

The easiest way I can think of to do this would be to pick an element ( say, h1 ) and use a stylesheet like this:

h1 {
  page-break-before: always;
}

body {
  background-color: black;
  color: white;
}

li {
  color: red;
}

calling:

$ mkd2pdf -c /path/to/simple-line-breaks.css example.md simple-line-breaks.pdf

would give us this pdf.