Search code examples
org-modepandocodt

How to convert Org mode file to ODT using a template and Pandoc?


I have a file plan.org with following contents:

* Hello!

  This is a test.

I want to convert it to LibreOffice (ODT) format using Pandoc so that it is formatted according to a template draft.ott or draft-template.odt both of which are available here.

When I run

cat plan.org | \
    pandoc -f org \
       -t odt \
       --template=draft-template.odt \
       --log=plan.odt.log \
       --fail-if-warnings \
       -o plan.odt

I get the error

pandoc: Cannot decode byte '\xc6': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream

The call

cat plan.org | \
    pandoc -f org \
       -t odt \
       --reference-doc=draft-template.odt \
       --log=plan.odt.log \
       --fail-if-warnings \
       -o plan.odt

does not generate any errors, but the resulting document plan.odt is not formatted according to draft-template.odt.

Same problem with

cat plan.org | \
    pandoc -f org \
       -t odt \
       --reference-doc=draft.ott \
       --log=plan.odt.log \
       --fail-if-warnings \
       -o plan.odt

How can I make sure that the resulting file plan.odt is using the fonts specified in draft.ott or draft-template.odt?

I am using pandoc 2.11.3.1, compiled with pandoc-types 1.22, texmath 0.12.0.3, skylighting 0.10.2, citeproc 0.3.0.1, ipynb 0.1.0.1 under MacOS BigSur 11.1.

Update 1: Adding

  • #+ODT_STYLES_FILE: "draft-template.odt" or
  • #+ODT_STYLES_FILE: "draft.ott"

to plan.org did not solve the problem.

Update 2: I tried exporting the default template using pandoc -D odt > template.odt, then replacing Courier New with Courier Prime in template.odt and then generating the ODT file using

pandoc plan.org \
   -f org \
   -t odt \
   --standalone \
   --template=template.odt \
   --log=plan.odt.log \
   --fail-if-warnings \
   -o plan.odt

Still no luck.

Update 3: file plan.org returns

plan.org: ASCII text

Update 4: The call

iconv -t utf-8 plan.org | \
pandoc plan.org \
   -f org \
   -t odt \
   --standalone \
   --template=template.odt \
   --log=plan.odt.log \
   --fail-if-warnings \
   -o plan.odt

did not work (plan.odt does not have the formatting from template.odt).


Solution

  • Following

    https://pandoc.org/MANUAL.html#character-encoding

    try

    iconv -t utf-8 plan.org | pandoc | iconv -f utf-8
    

    (Sorry not to answer this question in a comment. I do not have 50 points)