Bounding Unicorns

How To Install unoconv On Debian

unoconv is a program for converting any documents that can be read by OpenOffice/LibreOffice into formats that OpenOffice/LibreOffice can write. I use it most commonly to convert MS Word documents (.docx) to PDF files, but docx/odt to text, MS Excel/xlsx to CSV and others are possibilities as well.

There are several programs for MS Word to PDF conversion in particular, and there are other wrappers for/interfaces to OpenOffice/LibreOffice, but unoconv covers a wide range of formats, is relatively easy to set up, and has bindings developed for it in several languages. Hence we are going to get unoconv configured and operational.

Devuan Ascii / Debian Stretch

Getting unoconv to work on a modern Debian should be straightforward.

Install unoconv itself:

apt-get install unoconv

Then install appropriate LibreOffice components depending on what type of documents you wish to convert:

apt-get install libreoffice-writer libreoffice-calc

This should be it! Give unoconv a try with

unoconv -f pdf document.docx

Debian Squeeze

Debian Squeeze required some effort for unoconv to work. The two gotchas were 1) needing to install LibreOffice components if they were not already installed, ond 2) needing to install Uno bindings as they are also standalone.

OpenOffice or LibreOffice?

Squeeze ships with OpenOffice. Newer versions of Debian have LibreOffice, and LibreOffice is also available in squeeze-backports repository. While trying to troubleshoot the installation I switched to LibreOffice from backports, therefore that is what I will use in the following instructions.

Instructions for configuring squeeze-backports APT repository are available here.

Install LibreOffice

Since I am going with LibreOffice, I will install it in its own step.

apt-get install -t squeeze-backports libreoffice-core libreoffice-writer

For MS Word file conversion libreoffice-writer is needed. For MS Excel file conversion, liberoffice-calc, and so on.

The core package is a dependency of unoconv. The important part is also including one of the actual LibreOffice programs, like libreoffice-writer above. Those are not required by unoconv but not having any programs installed will produce the following error when attempting a conversion:

% unoconv -f pdf example.odt 
unoconv: UnoException during conversion: Unsupported URL <file:///home/sandbox/example.odt>: ""
The provided document cannot be converted to the desired format.

Install LibreOffice Python bindings

These must be installed from the same source that LibreOffice was installed from, in my case squeeze-backports:

apt-get install -t squeeze-backports python-uno

Install Java

unoconv requires libreoffice-java-common package and a JRE. Despite libreoffice-java-common bringing in some gij packages, they do not count for a JRE.

I chose to go with openjdk-6-jre.

apt-get install openjdk-6-jre
apt-get install -t squeeze-backports libreoffice-java-common

LibreOffice listener

unoconv requires a LibreOffice listener to be running. unoconv can launch it on demand, or you can launch it yourself.

To launch manually run:

unoconv --listener

Important thing to remember if manually launching the listener: the running listener is not affected by package installations and deinstallations. For example, if you launched the listener when libreoffice-writer was not installed, then you instaled libreoffice-writer, and subsequently you are trying to run unoconv, unoconv will use the runnning listener which has no knowledge of Writer and conversion will fail. Make sure to kill/restart listeners after installing or deinstalling LibreOffice components.

Done

With all of the above done unoconv should work:

unoconv -f pdf example.odt

Other Document Conversion Options