π

Using Template Files for Pandoc Exports to Word or LibreOffice

Show Sidebar

The amazing @pdfkungfoo tweeted about a nice feature of Pandoc, the universal document conversion tool:

Lade das Vorlagen-Muster in Word (.dot / .docx -- egal), mache evtl. gew├╝nschte Anpassungen an'n Stilen + speicher's als DOCX (nicht DOT) unter "my-reference.docx". Dann:

#pandoc input --reference-docx=my-reference.docx -o out.docx

Wirklich erstaunlich, wie viel da geht!

— pdfkungfoo (@pdfkungfoo) October 30, 2017

According to the manual, the option =--reference-doc=FILE= may define a docx (Word) or odt (LibreOffice) document which is used as a format template file.

So if you do have a company template for arbitrary Word files, you could use it as a template for your export. Copy a docx file (not a dotx template) as reference.docx to either:

  1. the current folder OR
  2. a folder which is defined by --data-dir OR
  3. the system default folder for data-dir which is
    • $HOME/.pandoc on UNIX-like systems
    • C:\Documents And Settings\USERNAME\Application Data\pandoc on Windows XP you should not use any more
    • C:\Users\USERNAME\AppData\Roaming\pandoc on Windows Vista or later.

So I took a company docx, renamed it to reference.docx and copied it to C:\Users\USERNAME\AppData\Roaming\pandoc on my Windows 10. When I now export from my Emacs Org-mode to a docx file (via ox-pandoc), I get documents that follow the style of our company documents: fonts, font colors, and even the company logo.

Awesome and nifty feature.

The only thing left is that I do have to learn how to avoid Emacs opening the resulting docx file as ZIP file in a buffer instead of opening it in Word.

Comment via email or via Disqus comments below: