Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...