Supported Formats
From (any of) | To (any of) |
Text Formats | |
OpenDocument Text (*.odt) OpenOffice.org 1.0 Text (*.sxw) Rich Text Format (*.rtf) Microsoft Word (*.doc) WordPerfect (*.wpd) Plain Text (*.txt) HTML1 (*.html) | Portable Document Format (*.pdf) OpenDocument Text (*.odt) OpenOffice.org 1.0 Text (*.sxw) Rich Text Format (*.rtf) Microsoft Word (*.doc) Plain Text (*.txt) HTML2 (*.html) MediaWiki wikitext (*.wiki) |
Spreadsheet Formats | |
OpenDocument Spreadsheet (*.ods) OpenOffice.org 1.0 Spreadsheet (*.sxc) Microsoft Excel (*.xls) Comma-Separated Values (*.csv) Tab-Separated Values (*.tsv) | Portable Document Format (*.pdf) OpenDocument Spreadsheet (*.ods) OpenOffice.org 1.0 Spreadsheet (*.sxc) Microsoft Excel (*.xls) Comma-Separated Values (*.csv) Tab-Separated Values (*.tsv) HTML2 (*.html) |
Presentation Formats | |
OpenDocument Presentation (*.odp) OpenOffice.org 1.0 Presentation (*.sxi) Microsoft PowerPoint (*.ppt) | Portable Document Format (*.pdf) Macromedia Flash (*.swf) OpenDocument Presentation (*.odp) OpenOffice.org 1.0 Presentation (*.sxi) Microsoft PowerPoint (*.ppt) HTML2 (*.html) |
Drawing Formats | |
OpenDocument Drawing (*.odg) | Scalable Vector Graphics (*.svg) Macromedia Flash (*.swf) |
Starting OpenOffice.org as a service
%OpenOffice_home%/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
Usage as a Command Line Tool |
To use JODConverter from the command line, download the jodconverter-2.2.0.zip distribution, unpack and execute the jodconverter-cli-2.2.0.jar JAR with java.
To convert a single file specify input and output files as parameters
java -jar lib/jodconverter-cli-2.2.0.jar document.doc document.pdf
To convert multiple files to a given format specify the format using the -f (or --output-format) option and then pass the input files as parameters
java -jar lib/jodconverter-cli-2.2.0.jar -f pdf *.odt
Usage as a Java LibrarySubmitted by mirko on 13 February 2007 - 3:35pm |
Using JODConverter in your own Java application is very straightforward. The following example shows the skeleton code required to perform a one off conversion from a Word document to PDF:
File inputFile = new File("document.doc"); File outputFile = new File("document.pdf"); // connect to an OpenOffice.org instance running on port 8100 OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); connection.connect(); // convert DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(inputFile, outputFile); // close the connection connection.disconnect();
To convert from/to other formats, simply change the file names and the formats will be determined based on file extensions; e.g. to convert an Excel file to OpenDocument Spreadsheet:
File inputFile = new File("spreadsheet.xls"); File outputFile = new File("spreadsheet.ods"); converter.convert(inputFile, outputFile);
Simple, isn't it? Yet this example actually shows almost everything you need to know for most applications.
Almost because establishing a new connection each time you need to do a conversion, while perfectly acceptable, is not the best idea from a performance point of view.If you're integrating JODConverter in a web application for example you may want to initialise a single OpenOfficeConnection instance when the app is started and disconnect it when the app is stopped.
There are many different ways to do this depending on which web framework (if any) you're using so I'm not going to explain it here. For plain Servlet API you can use a context listener, for Spring you can initialise the OpenOfficeConnection and DocumentConverter beans in your applicationContext.xml, and so on.