May 9, 2007

Extending Turning into a document conversion tool

Author: Dmitri Popov

One of the less well-known features of is its ability to run as a service. You can put that ability to some clever use. For example, you can turn OpenOffice.og into a conversion engine and use it to convert documents from one format to another via a Web-based interface or a command-line tool. JODConverter can help you to unleash's file conversion capabilities.

To be able to use as a conversion engine, you have to start it as a service. This means launching it without its GUI and making it listen for incoming connections on a particular port. To do this, launch using the following command on Linux:

soffice -headless -accept="socket,port=8100;urp;"

On Windows, use this command:

"C:\Program Files\ 2.2\program\soffice" -accept="socket,port=8100;urp;"

Since JODConverter is Java-based, you have to make sure that the Java runtime environment version 1.4 or higher is installed on your machine. Download the latest version of the package and extract it into your home directory. You can then launch the JODConverter using the script (start.bat on Windows) in the bin directory:

sh jodconverter-tomcat-2.1.1/bin/

On Ubuntu, you may get an error message telling you that the JAVA_HOME variable is not set. To fix this problem, locate your Java Runtime Environment using the locate /rt.jar command, and then set the variable as follows (using the directory the locate command reports):

export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun-

To avoid doing this manually every time you run JODConverter, add the above command to your /home/user/.bashrc file, or to the /etc/bash.bashrc file, if you want to add it for all users.

Now, point your browser to http://localhost:8080/converter and you should see a simple Web interface. Pick the file you want to convert, select the target format, and press the Convert! button.

The above description assumes that you are running and JODConverter on the same machine. However, it's possible to configure JODConverter to connect to running as a service on another machine. The Art of Solving Web site provides a description of how to go about it.

Converting documents from the command line is equally easy. Download the latest package and extract it into your home directory. Make sure that is running as a service, and use the java -jar lib/jodconverter-2.1.1.jar command to convert documents. For example:

java -jar jodconverter-2.1.1/lib/jodconverter-2.1.1.jar loremipsum.odt loremipsum.pdf

That's all there is to it. The created document conversion tool is ideal for converting files that come from any computer without running on it.

Dmitri Popov is a freelance writer whose articles have appeared in Russian, British, US, German, and Danish computer magazines.

Click Here!