Java JODConvert 3.0最佳实践

Java: JODConverter 3.x Getting Started

April 9th, 2009 by jeremychone

Requirements:

  • OpenOffice installed and OpenOffice started (e.g., OpenOffice in the system tray on Windows)
  • Java

Quick steps to test:

  1. Download the latest JODConverter 3.x from google code.
  2. Unzip the jar file
  3. Do a quick test:
    java -jar lib/jodconverter-${version}.jar test.odt test.pdf
  4. you should see something like
    C:\apps\jodconverter-3.0-beta-1>java -jar lib/jodconverter-3.0-beta-1.jar test.odt test.pdf
    
    Apr 9, 2009 12:56:42 PM net.sf.jodconverter.office.OfficeProcess start
    INFO: starting process with acceptString 'socket,host=127.0.0.1,port=8100' and
    profileDir 'C:\Users\JEREMY~1\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-8100'
    Apr 9, 2009 12:56:42 PM net.sf.jodconverter.office.OfficeProcess start
    INFO: started process; pid -1
    Apr 9, 2009 12:56:47 PM net.sf.jodconverter.office.OfficeConnection connect
    INFO: connected: 'socket,host=127.0.0.1,port=8100'
    Apr 9, 2009 12:56:52 PM net.sf.jodconverter.office.OfficeConnection$1 disposing
    INFO: disconnected: 'socket,host=127.0.0.1,port=8100'
    Apr 9, 2009 12:56:53 PM net.sf.jodconverter.office.ManagedOfficeProcess doEnsureProcessExited
    INFO: process exited with code 0

Note: As you can see it works because it assumes that OpenOffice listen to the port 8100, which happen to be the case (how lucky!).

In a Java (Server) App:

  1. Copy the following .jar files in your webapp lib directory
    lib/jodconverter-3.0-beta-1.jar
    lib/juh-3.0.0.jar
    lib/jurt-3.0.0.jar
    lib/ridl-3.0.0.jar
    lib/unoil-3.0.0.jar
  2. Use the following code snippet:
    OfficeManager officeManager = new ManagedProcessOfficeManager();
    officeManager.start();
    
    OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
    converter.convert(sourceFile,targetFile);
    
    officeManager.stop();

Best Practice (from JODConverter group)

  1. OfficeManager instance can and should be shared across all
    threads
    . It should typically be started when your webapp starts, and
    stopped when the webapp stops. It can be e.g. a singleton, or a Spring
    bean, or other equivalent approach of your choice.
  2. The OfficeDocumentConverter instance can also be shared, or you can
    create a different instance per thread. It doesn’t really matter,
    since all conversions will be delegated to the OfficeManager anyway.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值