openoffice doc转PDF

wangjiangbo2 2012-01-30 02:48:17
我用openoffice把doc文件转PDF,发生错误

java.lang.NoClassDefFoundError: com/sun/star/comp/helper/Bootstrap
at com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection.connect(AbstractOpenOfficeConnection.java:61)



我下载源文件发现61行是 XComponentContext localContext = Bootstrap.createInitialComponentContext(null);



Bootstrap所在的jar包我已引进到项目里
...全文
669 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuguichuan666 2014-04-24
  • 打赏
  • 举报
回复
cai5 楼主是什么啊?
wangjiangbo2 2012-01-30
  • 打赏
  • 举报
回复
解决了,我换上cai5 的版本jar包就不存在这个问题
wangjiangbo2 2012-01-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 cai5 的回复:]
commons-cli-1.0.jar
commons-io-1.3.1.jar
jodconverter-2.2.1.jar
jodconverter-cli-2.2.1.jar
juh-2.3.0.jar
jurt-2.3.0.jar
ridl-2.3.0.jar
slf4j-api-1.4.3.jar
slf4j-jdk14-1.4.3.jar
unoil-2.3.0.ja……
[/Quote]


jar包我都有,版本都比你这个新,我下个老版本试试
wangjiangbo2 2012-01-30
  • 打赏
  • 举报
回复
编译的时候不报错,但程序执行到XComponentContext localContext = Bootstrap.createInitialComponentContext(null);
还是报java.lang.NoClassDefFoundError: com/sun/star/comp/helper/Bootstrap


AbstractOpenOfficeConnection.class为jodconverter-2.2.2.jar包里的类,



OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
8100端口我也用如下方法启动:
cd C:\Program Files\OpenOffice.org 3\program

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






MiceRice 2012-01-30
  • 打赏
  • 举报
回复
那么另一个问题是:
com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection 这个类所在的JAR包,跟Bootstrap的JAR包,是在同一个装载层级的么?

或者说,你是怎么引入AbstractOpenOfficeConnection的JAR包的?如果是直接配置到CLASSPATH的话,那么Bootstrap的JAR包也需要配置到CLASSPATH中去。
五哥 2012-01-30
  • 打赏
  • 举报
回复
commons-cli-1.0.jar
commons-io-1.3.1.jar
jodconverter-2.2.1.jar
jodconverter-cli-2.2.1.jar
juh-2.3.0.jar
jurt-2.3.0.jar
ridl-2.3.0.jar
slf4j-api-1.4.3.jar
slf4j-jdk14-1.4.3.jar
unoil-2.3.0.jar
xstream-1.2.2.jar

就这些 jar包 ,之前写的 ,可以的,必须启动openOffice,

cd C:\Program Files\OpenOffice.org 3\program
>soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
五哥 2012-01-30
  • 打赏
  • 举报
回复

package com.chinacreator.test;

import java.io.File;
import java.net.ConnectException;
import java.util.Date;

import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;



public class JOD4DocToPDF {

public void docToPdf(File inputFile, File outputFile){
Date start = new Date();
// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
try{
connection.connect();

// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
}catch(ConnectException cex){
cex.printStackTrace();
}finally{
// close the connection
if(connection!=null){
connection.disconnect();
connection = null;
}
}
long l = (start.getTime()- new Date().getTime());
long day=l/(24*60*60*1000);
long hour=(l/(60*60*1000)-day*24);
long min=((l/(60*1000))-day*24*60-hour*60);
long s=(l/1000-day*24*60*60-hour*60*60-min*60);
System.out.println("生成"+outputFile.getName()+"耗费:"+min+"分"+s+"秒");
}

class TestThread extends java.lang.Thread{
public File inputFile;
public File outputFile;

public void run(){
JOD4DocToPDF t = new JOD4DocToPDF();
t.docToPdf(inputFile, outputFile);
System.out.println(outputFile.getName()+"文件已生成");
}
}

public void test(){
TestThread t1 = new TestThread();
t1.inputFile = new File("d:/document.doc");
t1.outputFile = new File("d:/document.pdf");


TestThread t2 = new TestThread();
t2.inputFile = new File("d:/document2.doc");
t2.outputFile = new File("d:/document2.pdf");

TestThread t3 = new TestThread();
t3.inputFile = new File("d:/document3.doc");
t3.outputFile = new File("d:/document3.pdf");


t2.start();
t1.start();
t3.start();
}

public static void main(String[] args) throws Exception{
JOD4DocToPDF p = new JOD4DocToPDF();
p.test();

}

}
wangjiangbo2 2012-01-30
  • 打赏
  • 举报
回复

public void docToPdf() {
Date start = new Date();
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);

try {
XComponentContext localContext = Bootstrap.createInitialComponentContext(null);
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
} catch (Exception cex) {
cex.printStackTrace();
} finally {
// close the connection
connection.disconnect();
}
}


我随便在一个java里加入 XComponentContext localContext = Bootstrap.createInitialComponentContext(null);
是不报错的
MiceRice 2012-01-30
  • 打赏
  • 举报
回复
错误信息是找不到 com.sun.star.comp.helper.Bootstrap

你说“Bootstrap所在的jar包我已引进到项目里”

但JVM是不会骗人的,所以还是只能自己检查检查实际的运行环境了。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧