My Technical Notes

Monday, 27 March 2017

Converting ORG to PDF with custom CSS styling

OrgMode is a very simple and easy to use plugin for Emacs that allows you to organize yourself using text only.

One drawback of it is that Emacs/OrgMode has a high learning curve: too many keyboard shortcuts to remember, requires use of lisp to customise output etc.

However, its main strength is that OrgMode files are purely text - and text is very easy to process.

Emacs OrgMode already has PDF output capability (via LaTeX). However, to style its output, you have to use custom Lisp functions containing LaTeX code. As I am unfamiliar with both LaTeX and Lisp, I wanted to use familiar technologies, such as CSS, to style the content, and use Emacs purely for editing the OrgMode files.

Installing Pandoc   Pandoc needs to be installed first.

Installing wkhtmltopdf   wkhtmltopdf also needs to be installed because that is what actually does the HTML to PDF conversion. You also have to add `C:\Program Files\wkhtmltopdf\bin` to the `PATH` variable so it is visible to Pandoc.

Including CSS   Below is a sample css file `sample.css` which makes `.done` tasks green:

.done {
    color: green;

Place it in the same folder as the `.org` folder for the commands below, which reference its path, to work.

OrgMode file   The commands will be run against the following OrgMode file, ``:

* DONE this is a done task
* DONE this is a second done task.

Pandoc Command   Execute the following command to create `doc.pdf` from ``:

pandoc -t html5 --css sample.css -o doc.pdf

The `-t html5` in the command ensures that it uses `wkhtmltopdf` to create the PDF document instead of LaTeX.


  • An answer explaining the user of pandoc to convert OrgMode to PDF

No comments: