Automated conversion and styling using LibreOffice
Universal Office Converter (unoconv) is a command line tool to convert any document format that LibreOffice can import to any document format that LibreOffice can export. It makes use of the LibreOffice’s UNO bindings for non-interactive conversion of documents.
For practical reasons we mention LibreOffice, but OpenOffice is supported by unoconv as well.
Installing unoconv
unoconv can be installed using packages coming from your distribution, or simply by copying the unoconv python script to your system.
If you installed unoconv by hand, make sure you have the required LibreOffice or OpenOffice packages installed. A hard requirement is the UNO python bindings which are often inside a subpackage named libreoffice-pyuno or libobasis4.4-pyuno.
Various sub-packages are needed for specific import or export filters, e.g. XML-based filters require the xsltfilter subpackage, e.g. libobasis4.4-xsltfilter.
Important
Neglecting these requirements will cause unoconv to fail with unhelpful and confusing error messages.
How does unoconv work ?
unoconv starts its own office instance (if it cannot find an existing listener) that it then uses. There are some challenges to do this correctly, but in general this works fine.
Typically you would convert an ODT document to PDF by running:
unoconv -f pdf some-file.odt
Start your own unoconv listener
However, you can always start an instance yourself at the default port 2002 (or specify another port with -p/--port) and after use you can tear it down:
unoconv --listener &
sleep 20
unoconv -f pdf *.odt
unoconv -f doc *.odt
unoconv -f html *.odt