Rss Feed Tweeter button Facebook button Technorati button Reddit button Linkedin button Webonews button Delicious button Digg button Flickr button Stumbleupon button Newsvine button

A Waage Blog

Ruby, Rails, Life

OpenOffice Headless Mode Installation Word doc to pdf conversion

with 7 comments

How to set up OpenOffice to run in headless mode on Fedora 9

What we wanted was a system set up to convert any OpenOffice document to PDF. Most importantly, we needed to convert Word .doc files to .pdf, but in fact, any OpenOffice file types (.xls, .odt, .txt, .rtf, etc) will work, as long as you install the proper packages / dependencies!

Also important:
We will be starting OpenOffice in headless mode, which means no GUI. This should be started on boot up, and should just run in the background.

Install:
You don’t need to install all the OpenOffice packages if you don’t need them. We are mainly concerned with Word docs, so OoWriter is a must. We are running in headless mode, which means we don’t have a GUI to openoffice. So we can leave out a bunch of unnecessary packages.

- Here’s what we have installed:

openoffice.org-core.x86_64  1:2.4.2-18.3.fc9 installed
openoffice.org-headless.x86_64 1:2.4.2-18.3.fc9 installed
openoffice.org-pyuno.x86_64 1:2.4.2-18.3.fc9 installed
openoffice.org-sdk.x86_64 1:2.4.2-18.3.fc9 installed
openoffice.org-writer.x86_64 1:2.4.2-18.3.fc9 installed
openoffice.org-writer2latex.x86_64 0.5-2.fc9 installed

If you need to convert Excel spreadsheets, ppt Powerpoint presentations to pdf, you will need to install the corresponding package (ie. openoffice.org-calc, openoffice.org-draw, etc.)

After you have these packages installed, be sure you have the soffice command. By default it is here:
/usr/lib64/openoffice.org/program/soffice.bin

Next, try to start up the service with this command:

$ /usr/lib64/openoffice.org/program/soffice.bin -headless accept="socket,host=localhost,port=8100;urp;" -nofirststartwizard &

#Note: the ampersand (&) allows the command to run in background so you get your shell back.
You can specify whichever port you would like. The -nofirststartwizard flag does exactly that.

Next step is to find a script (client) that can interact with this OpenOffice service.
A few options are:
1. dag’s unoconv (Available from yum)
http://dag.wieers.com/home-made/unoconv/
2. PyODConverter – a cool Python script to do conversions
http://www.artofsolving.com/opensource/pyodconverter
3. Write your own!

We chose to use PyODConverter. It’s simple to use:

$ PyODConverter.py example.doc example.pdf

Lastly, I mentioned that we want this soffice to start up everytime we reboot.

Simply add the line to your /etc/rc.d/rc.local

# Start up openoffice for fax conversion
$ /usr/lib64/openoffice.org/program/soffice.bin -headless accept="socket,host=localhost,port=8100;urp;" -nofirststartwizard

And there you have it. Hope that helps somebody. Happy Conversions!

Hint: If you are getting strange unintelligible errors about “URL seems to be an unsupported one”, it may be that you have not installed a necessary openoffice package. That’s how I discovered I needed OoWriter …

Written by Andrew Waage

September 17th, 2009 at 2:30 pm

7 Responses to 'OpenOffice Headless Mode Installation Word doc to pdf conversion'

Subscribe to comments with RSS or TrackBack to 'OpenOffice Headless Mode Installation Word doc to pdf conversion'.

  1. Have you used this inside rails?

    Chris P.

    22 Apr 10 at 11:49 am

  2. @chrisp Not directly – although you could call it from any Ruby / Rails script. Are you having problems using it w/ Rails ?

    Qug

    22 Apr 10 at 1:36 pm

  3. Hi. Do you know what happens with concurrent requests for conversion? Does OO handle that, or would I have to manage the conversion queue myself?

    Thanks for the post.

    P.S. Is there a way to do this on Windoze as well using OO?

    Warwick

    27 Aug 12 at 9:12 pm

  4. @warwick – it’s been so long since I wrote this, but I believe you will have to manage the conversion queue yourself. I also have not tried with Windows, but as long as headless mode is supported, I would imagine it would work. Good luck!

    Andrew Waage

    28 Sep 12 at 11:52 am

  5. I’m unable to use the PyODConverter for conversions every time I try to execute it from the terminal I get a syntax error from the python file I downloaded on the very first line. I have a feeling it has something to do with the interpretation of the script but i’m not sure.

    As far as I can tell I have done no Editing to the original file I have downloaded @ https://github.com/mirkonasato/pyodconverter/blob/master/DocumentConverter.py

    Kindly help me out

    Nick

    7 Oct 12 at 7:56 am

  6. The error Just in case you need to see what it gives me

    ./PyODConverter.py example.doc example.pdf
    ./PyODConverter.py: line 1: syntax error near unexpected token `newline’
    ./PyODConverter.py: line 1: `’

    Nick

    7 Oct 12 at 7:57 am

  7. @Nick, it looks like the PyODConverter.py script doesn’t have the hashbang at the top that specifies to use the python interpreter.

    You might want to try running it like this:

    $> python PyODConverter.py example.doc example.pdf

    If you’re not familiar w/ the #! syntax (Hashbang), see this link for more info: http://forums.opensuse.org/english/other-forums/development/programming-scripting/404906-how-execute-python-script.html

    Hope that helps!

    Andrew Waage

    7 Oct 12 at 11:44 am

Leave a Reply