I'm looking for a solution (consisting of one or more tools) which allows me to implement a personal document workflow to deliver documents of a professional nature with a minimal of repetitive work (e.g. styling).
The idea behind it is that I often have to write documents where the content differs, but the styling is always limited to a handful of layouts. Currently, these documents are written in Microsoft Word, but I find that I spend too much time fiddling with the layout and that it is distracting me from what matters, i.e. the content.
As a test, I wrote one document in plain text first (well, Markdown actually) and found that I was able to focus much better on the writing itself. The penalty came afterwards when having to piece everything back into Word.
These are the requirements:
- Be able to define templates. These templates should contain style definitions (headers, colours, logo, …).
- Write content using plain text with minimal markup for styling. Ideally, this would be something like Markdown or reStructuredText.
- Generate table of contents, support for headers and footers, …
- Export to PDF is crucial.
- Run on OS X.
- A command-line interface.
Nice to have:
- Templates which support the use metadata (defined separately) to automatically create a distribution list, version overview … .
- Export to different file types (e.g. doc(x), HTML, …).
A solution that would allow HTML + CSS would probably work too, as I can convert Markdown, RST, ... to HTML (using an intermediate conversion engine).
I would prefer a tool instead of a pure API library, though the latter is welcome as an addition and to implement further customisation. In that case, the API has to support Python 3.
What I've evaluated so far:
- Pandoc: Uses Latex to export to PDF. While in theory I could define Latex templates, the learning curve of Latex for what I needed it was prohibitively steep. The conversion of MD tables to PDF was also rather lacking. From what I've gathered, using reStructuredText could be a solution for the table issue.
- Prince: A commercial solution. This was a fairly close match to my requirements, however the lack of clear documentation (both official documentation and information found in the forum) was a big let down.
- xhtml2pdf: HTML/CSS to PDF converter based on Python. This falls somewhere between a pure API and a tool you can use out of the box. It's based on the well known ReportLab PDF generation engine. The problem with xhtml2pdf is that Python 3 support is still largely broken in the current version (0.0.6).
In the end, I've settled for the following combination:
- Python-Markdown: converts the Markdown source document to HTML
- Jinja2: provides the necessary template features
- PyYAML: metadata is entered in a separate YAML file and read with PyYAML
- Weasyprint: performs the final conversion of HTML to PDF
While they're different tools/libraries, I was able to combine them rather easily using Python, allowing me to create a PDF document formatted using CSS documents.
However, I'm still selecting No-nonsense's suggestion Docxpresso as the "correct" answer, as it has one important advantage: Docxpresso generates ODF files, which still allows you to make minor modifications before the conversion to the final PDF file.