Package: unoserver-fork
Using LibreOffice as a server for converting documents.OverviewUsing LibreOffice to convert documents is easy, you can use a command like this to
convert a file to PDF, for example:$ libreoffice --headless --convert-to pdf ~/Documents/MyDocument.odfHowever, that will load LibreOffice into memory, convert a file and then exit LibreOffice,
which means that the next time you convert a document LibreOffice needs to be loaded into
memory again.To avoid that, LibreOffice has a listener mode, where it can listen for commands via a port,
and load and convert documents without exiting and reloading the software. This lowers the
CPU load when converting many documents with somewhere between 50% and 75%, meaning you can
convert somewhere between two and four times as many documents in the same time using a listener.Unoserver contains two commands to help you do this,unoserverwhich starts a listener on the
specified IP interface and port, andunoconverterwhich will connect to a listener and ask it
to convert a document.InstallationNB! Windows and Mac support is as of yet untested.Unoserver needs to be installed by and run with the same Python installation that LibreOffice uses.
On Unix this usually means you can just install it with:$ sudo pip install unoserverIf you have multiple versions of LibreOffice installed, you need to install it for each one.
Usually each LibreOffice install will have it’s ownpythonexecutable and you need to runpipwith that executable:$ sudo /full/path/to/python -m pip install unoserverTo find all Python installations that have the relevant LibreOffice libraries installed,
you can run a script calledfind_uno.py:wget -O find_uno.py https://gist.githubusercontent.com/regebro/036da022dc7d5241a0ee97efdf1458eb/raw/find_uno.py
python3 find_uno.pyThis should give an output similar to this:Trying python found at /usr/bin/python3... Success!
Trying python found at /opt/libreoffice7.1/program/python... Success!
Found 2 Pythons with Libreoffice libraries:
/usr/bin/python3
/opt/libreoffice7.1/program/pythonThe/usr/bin/python3binary will be the system Python used for versions of
Libreoffice installed by the system package manager. The Pythons installed
under/opt/will be Python versions that come with official LibreOffice
distributions.To install on such distributions, do the following:$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo /path/to/python get-pip.py
$ sudo /path/to/python -m pip install unoserverYou can also install it in a virtualenv, if you are using the system Python
for that virtualenv, and specify the--system-site-packagesparameter:$ virtualenv --python=/usr/bin/python3 --system-site-packages virtenv
$ virtenv/bin/pip install unoserverWindows and Mac installs aren’t officially supported yet, but on Windows the
paths to the LibreOffice Python executable are usually in locations such asC:\Program Files (x86)\LibreOffice\python.exe. On Mac it can be for
example/Applications/LibreOffice.app/Contents/python.UsageInstalling unoserver installs two scripts,unoserverandunoconverter.
Both can also be run as modules withpython3 -m unoserver.serverandpython3 -m unoserver.converterwith the same arguments as the main scripts.Unoserverunoserver[-h][--interfaceINTERFACE][--portPORT][--daemon][--executableEXECUTABLE]–interface: The interface used by the server, defaults to “localhost”–port: The port used by the server, defaults to “2002”–daemon:  Deamonize the server–executable: The path to the LibreOffice executableUnoconvertunoconvert[-h][--convert-toCONVERT_TO][--interfaceINTERFACE][--portPORT] infile outfileinfile: The path to the file to be converted (use - for stdin)outfile: The path to the converted file (use - for stdout)–convert-to: The file type/extension of the output file (ex pdf). Required when using stdout–interface: The interface used by the server, defaults to “localhost”–port: The port used by the server, defaults to “2002”Development and TestingClone the repo fromhttps://github.com/unoconv/unoserver.Setup a virtualenv:$ virtualenv --system-site-packages ve
$ ve/bin/pip install -e .[devenv]Run tests:$ ve/bin/pytest testsRunflake8linting:$ ve/bin/flake8 src testsComparison withunoconvUnoserver started as a rewrite, and hopefully a replacement tounoconv, a module with support
for using LibreOffice as a listener to convert documents.Differences for the userEasier install for system versions of LibreOffice. On Linux, the apckaged versions of LibreOffice
typically uses the system Python, making it easy to installunoserverwith a simplesudo pip install unoservercommand.Separate commands for server and client. The client no longer tries to start a listener and then
close it after conversion if it can’t find a listener. Instead the newunoconverterclient
requires theunoserverto be started. This makes it less practical for one-off converts,
but as mentioned that can easily be done with LibreOffice itself.Theunoserverlistener does not prevent you from using LibreOffice as a normal user, while theunoconvlistener would block you from starting LibreOffice to open a document normally.You should be able to on a multi-core machine run severalunoserverswith different ports.
There is however no support for any form of load balancing inunoserver, you would have to
implement that yourself in your usage ofunoconverter.Only LibreOffice is officially supported. Other variations are untested.Differences for the maintainerIt’s a complete and clean rewrite, supporting only Python 3, with easier to understand and
therefore easier to maintain code, hopefully meaning more people can contribute.It doesn’t rely on internal mappings of file types and export filters, but asks LibreOffice
for this information, which will increase compatibility with different LibreOffice versions,
and also lowers maintenance.ContributorsLennart Regebro,regebro@gmail.comStephan Richter,srichter@shoobx.com1.3 (unreleased)Nothing changed yet.1.2 (2022-03-17)Move logging configuration from import time to the main() functions.Improved the handling of KeyboardInterruptAdded the deprecated but still necessary com.sun.star.text.WebDocument
for HTML docs.1.1 (2021-10-14)Fixed a bug: If you specified an unknown file extension while piping the
result to stdout, you would get a type error instead of the correct error.Added an extra check that libreoffice is quite dead when exiting,
I experienced a few cases where soffice.bin was using 100% load in the
background after unoserver exited. I hope this takes care of that.Addedif __name__ == "main":blocks so you can run the modules
as scripts, and also withpython3-munoserver.serverandpython3-munoserver.converter.1.0.1 (2021-09-20)Fixed a bug that meantunoserverdid not behave well with Supervisord’s restart command.1.0 (2021-08-10)A few small spelling and grammar changes.1.0b3 (2021-07-01)Make sureinterfaceandportoptions are honored.Added an –executable option to the server to pick a specific libreoffice installation.Changed the infile and outfile options to be positional.Added support for using stdin and stdout.Added a –convert-to argument to specify the resulting filetype.1.0b2 (2021-06-24)A bug prevented converting to or from files in the local directory.1.0b1 (2021-06-24)First beta release0.0.1 (2021-06-16)First alpha release