jodconverter

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 Library

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.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值