4

I am trying to convert my libre office document into an ms word document through the following command

pandoc CS141Exam.odt -f markdown -t docx -s -o test1.docx

but I'm getting the following errors

pandoc: Cannot decode byte '\xac': Data.Text.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream

What is the correct command to achieve this?

Mestica
  • 1,489
  • 4
  • 23
  • 33
  • 3
    `pandoc` can write to odt but not read from it. See [this list of input formats](http://pandoc.org/README.html#description). You can use the built-in converter in libreoffice : `libreoffice --convert-to docx CS141Exam.odt` – scoa May 13 '15 at 06:36
  • @scoa per your link, pandoc shd be able to read it: "It can read Markdown, CommonMark, PHP Markdown Extra, GitHub-Flavored Markdown, and (subsets of) Textile, reStructuredText, HTML, LaTeX, MediaWiki markup, TWiki markup, Haddock markup, OPML, Emacs Org mode, DocBook, txt2tags, EPUB, ODT and Word docx;" – Amanda Dec 15 '15 at 19:04

1 Answers1

5

You've got pandoc trying to convert "from" (-f) markdown, "to" (-t) docx. But you're giving it an odt file. So it's trying to read that odt as though it were markdown and choking, because it isn't markdown. You want something closer to:

pandoc CS141Exam.odt -f odt -t docx -s -o test1.docx

but... odt isn't supported until pandoc 1.15.1, so do pandoc -v to make sure you've got a current version, too. My Ubuntu stable repo gave me 1.12.4.2 -- I had to get the latest directly from pandoc, but then this worked fine for me:

pandoc -f odt -t docx -o example.docx example.odt 

(Though I don't have MS Word so all I know is that example.docx looks fine in LibreOffice Writer)

Amanda
  • 12,099
  • 17
  • 63
  • 91
  • 1
    You can also install pandoc from source to get the latest version (http://pandoc.org/installing.html). I would still recommend using libreoffice or openoffice (http://stackoverflow.com/questions/21845789/how-to-convert-docx-to-odt-with-libreoffice-on-ubuntu-bash) since pandoc will first translate the odt to native pandoc, then back to docx, losing some formatting in the process. – scoa Dec 15 '15 at 21:15