EUCOOKIELAW_BANNER_TITLE

  • I think that

    Making the Web is like playing a game. Standard, Accessibility and Usability are only few rules.
    No game is awesome if you don't follow the rules.

    International Webmasters Association

  • Subscribe to my blog via email

    Insert here your e-mail address and you will receive a message when a new post will come.

How to make libreoffice headless to work on CentOS 6.3

In the latest days I was wondering how to make a minimal file-server able to convert some documents readable from LibreOffice to PDF.

The first thing I’ve done was to install a Virtual Machine with CentOS 6.3 Minimal (No serverX, no WebServer… just, network and few other functionalities).

This post can be followed simply both by an high skilled user and by a dummy user. All steps are well documented and each command is adequatelly described.

Installation

Traveling through the yum repositories, I’ve found the libreoffice-headless (it means the openoffice without ServerX) then I’ve installed it using this simple command:

root@centos:/$ yum install libreoffice-headless

it should install all requirements, dependencies and then libreoffice 3.4 headless. It means the functionality to make LibreOffice to work on command line.

I’ve thought: “well I’ve done all I need… too easy!!!” so I’ve run the command:

root@centos:/$ libreoffice --headless --convert-to pdf mydocument.odt

The above command will convert the document from ODT format to PDF. The server freezes few seconds, the HD Led flashes two or three times and then the shell prompt was available again.

Great! I did a ls command but the pdf file wasn’t there… “Oh Damn!!!

Someone in the Web suggest to use JODconverter, someothers told that it is a bug of Libreoffice.

I found the solution without installing third-part software onto your minimal OS instead.

Just installing the writer will solve all your prolbems:

root@centos:/$ yum install libreoffice-writer

then after the OS has finished the installation process, run again

root@centos:/$ libreoffice --headless --convert-to pdf mydocument.odt

As you can notice you’ve done!

More document types

To enable PPT/ODP and XLS/ODS conversion you need to install either libreoffice-impress and libreoffice-calc packages with following commands:

root@centos:/$ yum install libreoffice-impress
root@centos:/$ yum install libreoffice-calc

Using a listner

Sometimes if you have several applications that need to convert documents on the fly and them are not installed on the same Server, you could consider to use the LibreOffice  headless with a listner on a Converter Server.

root@centos:/$ libreoffice --headless 
                --accept="socket,host=0,port=8001,tcpNoDelay=1;urp"
                --nodefault --nofirststartwizard --nolockcheck
                --nologo --norestore --invisible &

In this way another server can connect to the LibreOffice listner through the UNO API  on the defined port. Let’s describe most of the above parameters:

  • –accept Specify a UNO connect-string to create a UNO acceptor through which other programs can connect to access the API. In the above case it creates the acceptor on the port 8001 of this server (localhost).
  • –nodefault tells that no default document must be created at startup.
  • –nolockcheck disables the check for remote instances using the installation.
  • –nologo Disables the splash screen at program start.
  • –norestore Disables restart and file recovery after a system crash. It is possible that LO will try to restore a file it keeps crashing on, if that happens –norestore is the only way to start LO.
  • –nosplash Disables the splash screen at program start.
  • –invisible This prepares Libreoffice to be used as service because it’s available but not visible in background.

The last & is not a typing error: it tells the shell “do not wait for the end of the task, execute it and let me use the shell again”: simply “Multitasking” :-)

I want to know more

Most of the above details are reported from the man page of LibreOffice.

root@centos:/$ man libreoffice

More commands, options and features are heavly described there, some others less but it’s the best starting point!

And now? Have fun with document conversion! :-)

What’s next?

In the next days we will see how to apply those concept in a pratical Web Application using PHP. If you don’t want to miss it, follow me on Twitter or add a Like to my Facebook Fan Page or simply subscribe to the RSS Feed of this Web Site. However, stay tuned!

One thought on “How to make libreoffice headless to work on CentOS 6.3

  1. files using PHP. There are some native libraries, but I see that LibreOffice converts docs much better than others. I will run this script on server, so I don’t need GUI for this.