I am using libreoffice under CentOS 6. I can convert ODT files to PDF with:

libreoffice --headless --convert-to pdf *.odt but the problem is that it only works when no document is open in libreoffice.

When I specify --env:UserInstallation=file:///path/to/some/directory as suggested in one of the comments of this question , it doesn't help.

What am I doing wrong? It is a nuisance to close all libreoffice instances before running the before command.

4 Answers 4


One possible approach is to install unoconv (if not already installed) and

unoconv file.odt

Please see man unoconv for details

unoconv is a command line utility that can convert any file format that LibreOffice can import, to any file format that LibreOffice is capable of exporting. unoconv uses the LibreOffice’s UNO bindings for non-interactive conversion....

In some platforms it is also necessary to install libreoffice-headless \thanks{Aaron}

  • Under CentOS7, I also had to add the package libreoffice-headless to have it automated. If the user has never used it before, the first call to unoconv fails with error 81 after creating a bunch of files in ~/.config/. Feb 11, 2016 at 14:32
  • 1
    @AaronD.Marasco, thank you very much for this important information! Probably there is a dependency missing in the spec file. I will add your tip to the answer.
    – JJoao
    Feb 12, 2016 at 14:53
  • 1
    @JJoao, if you are a CentOS user, you should report your finding as a bug report.
    – vonbrand
    Feb 12, 2016 at 19:32
  • Not a spec dependency... just a use case. The error 81 issue is supposedly fixed but I don't know what version; I guess CentOS doesn't have it yet. Feb 12, 2016 at 19:34

That is unlikely going to work, as the suggestion in the comment is both incomplete (you cannot just specify some directory) and incorrect (--env:... should be -env:... Here is what I recommend you do:

  1. Stop all instances of libreoffice
  2. Start libreoffice from the commandline without specifying --headless:

    libreoffice -env:UserInstallation=file:///home/username/.config/libreoffice-alt

    you should replace /home/username with your home directory (and adjust .config if you don't have that on your CentOS, I did this on Ubuntu and Linux Mint). The above will create a new configuration directory for the alternate libreoffice in your .config directory, without which you would get some error about java not being found.

  3. Exit that instance of libreoffice
  4. That directory /home/username/.config/libreoffice-alt should now have been created for you.

Now start another libreoffice from the command-line (doing so allows you to see some useful messages if things go wrong when starting the second instance), without the -env:..., and while that is still running start the conversion using:

libreoffice -env:UserInstallation=file:///home/username/.config/libreoffice-alt --headless --convert-to pdf *.odt
  • PS I have .config as well on CentOS
    – Johan
    Apr 18, 2015 at 15:22
  • Instead of stopping all instances, you can simply log in as a different user, create the .config-files and copy those to your own home dir.
    – Ole Tange
    Feb 26, 2018 at 20:21
  • 1
    On an Ubuntu 16.04 machine, I just ran libreoffice --headless --convert-to pdf <filename>.odt and it did it, without those prep steps. It did print a warning about Java tho.
    – Kyle
    Aug 31, 2018 at 23:10

Here is a totally different approach.

It is possible, because in recent times a series of new conversion paths were opened by Pandoc's newly acquired capability to read ODT files.

When Pandoc reads in a file format, it converts it into an internal format, "native" (which is a form of JSON).

From its native form, it can then export the document into a whole range of other formats. Not only PDF, but also DocBook, HTML, EPUB, DOCX, ASCIIdoc, DokuWiki, MediaWiki and what-not...

Since here the wanted output format is PDF, we have another choice of different paths, provided by what Pandoc is calling a pdf-engine. Here is the list of currently available PDF engines (valid for Pandoc v2.7.2 and later -- previous versions may support only a smaller list):

  • pdflatex: This requires LaTeX to be installed in addition to Pandoc.

  • xelatex: This requires XeLaTeX to be installed in addition to Pandoc (also available as an additional package to general TeX distributions).

  • context: This requires ConTeXt to be installed in addition to Pandoc; ConTeXt is available as an additional package to most general TeX distributions).

  • lualatex: This requires LuaTeX to be installed in addition to Pandoc (also available as an additional package to general TeX distributions).

  • pdfroff: This requires GNU Roff to be installed in addition to Pandoc.

  • wkhtml2pdf: This requires wkhtmltopdf to be installed in addition to Pandoc.

  • prince: This requires PrinceXML to be installed in addition to Pandoc.

  • weasyprint: This requires weasyprint to be installed in addition to Pandoc.

There are some more and newer PDF engines now integrated into Pandoc, which I have not yet used myself and which I currently cannot describe in more detail: tectonic and latexmk.

WARNING: Do not expect that the appearance of your original document will be identical in all the PDF outputs to the print preview or PDF export of the ODT! Pandoc, when converting does not preserve layouts, it preserves the contents and the structure of documents: paragraphs remain paragraphs, emphasized words remain emphasized, headings remain headings, etc. But the overall look can change considerably.

Example commands


 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=pdflatex


 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=xelatex


 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=lualatex


 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=context

GNU troff:

 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=pdfroff


 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=wkhtml2pdf


 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=prince


 pandoc -f odt -o mydoc.pdf mydoc.odt --pdf-engine=weasyprint

Above commands are the most basic for the conversion. Depending on the PDF engine you pick, there may be many other options possible to control the appearance of the output PDF file. For example, the following additional parameters may be added to all those paths routing through LaTeX:

 -V geometry:"paperwidth=23.3cm, paperheight=1000pt, margin=11.2mm, top=2cm"

which will use a custom page size (a bit larger than DIN A4) with margins of 2cm on the top edge and 1.12cm at the other three edges).

  • Unfortunately pandoc doesn't support every libreoffice format; for example .ods (the spreadsheet format) is not supported. Nov 11, 2019 at 2:59
  • 1
    @Granitosaurus: The question was about ODT, hence this answer is appropriate. Nov 11, 2019 at 23:53
  • Oh I never implied it wasn't appropriate, just that it's unfortunate pandoc doesn't support many other libreoffice formats. Nov 14, 2019 at 5:47
  • @Granitosaurus: Pandoc is an OpenSource Software project. So you can easily contribute. If you're not into programming additional features into Pandoc, you at least can find their project on Github and are free to submit a Feature Request into their bug tracker. That also was what triggered Pandoc support for PowerPoint output to be added... Nov 14, 2019 at 12:37

You can try this :

$ libreoffice2 pdf *.odt

Anyway, this pb. has been fixed the libreoffice Team since at least libreoffice 6.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .