Converting office documents into PDF from the command line

Posted by berto on September 15, 2007

One of the best-known features of the OpenOffice.org suite is its ability to export files into PDF format.

Combined with the ability to read files in many formats such as the ones used in WordPerfect and MS Office, this makes OpenOffice.org a good converter.

Of course there are more free office converters (example: wvWare) but OpenOffice.org is probably the best one due to the large number of formats that is supports and the good quality of its filters.

Its main drawback, however, is that it’s not trivial to convert documents using this suite in batch mode from the command line.

Of all the methods I’ve seen, this is probably the easiest one. Here are the steps:

  1. Start OpenOffice.org:
    $ openoffice "-accept=socket,host=localhost,port=2002;urp;"
    
  2. Download this script.
  3. Use it!
    $ ./ooextract.py --pdf mydocument.odt
    

OpenOffice.org has to be running in background for this script to have effect, so to avoid the annoyance of having the office window laying around in your desktop (or to use it in a machine with no display) you can use Xvfb or a VNC server. Example:

$ Xvfb :1 &
$ DISPLAY=:1 openoffice "-accept=socket,host=localhost,port=2002;urp;"

And that’s it. It would be nice if OpenOffice.org had direct support for conversion from the command line, but meanwhile this method will do the job.

Endless summer

Posted by berto on September 03, 2007

Yeah, I know, I said the other day that summer had already ended…
Endless Summer
…well, I changed my mind, let’s wait a bit more ;-)