java使用openoffice将word转pdf时,出现could not save output document的问题

ZJJG4 2019-07-25 10:59:22
java使用openoffice将word转pdf时,报 2019-07-25 10:45:52 ERROR com.googosoft.resolver.MyExceptionResolver:33 - com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: conversion failed: could not save output document; OOo errorCode: 2074问题

下面是方法的代码:public static void WordToPDF(String startFile, String overFile) throws IOException, ConnectException { // 源文件目录
File inputFile = new File(startFile);
if (!inputFile.exists()) {
System.out.println("源文件不存在!");
return;
}
// 输出文件目录
File outputFile = new File(overFile);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().exists();
}
// 调用openoffice服务线程
/** 我把openOffice下载到了 C:/Program Files (x86)/下 ,下面的写法自己修改编辑就可以**/
String OpenOfficePath =PropertiesUtil.getGlobalValueByKey("OpenOfficePath");
String command=null;
/** windows 服务器调用的地址会带EXE **/
if(OpenOfficePath.indexOf(".exe")>0 || OpenOfficePath.indexOf(".EXE")>0) {
command = OpenOfficePath+" -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\"";
}
/** linux 不会带 **/
else {
command = "nohup "+OpenOfficePath+" -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard & ";
}
System.out.println("----------------------------------"+command+OpenOfficePath);
Process p = Runtime.getRuntime().exec(command);
// 连接openoffice服务
OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
connection.connect();
// 转换
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
//DocumentConverter converter = new StreamOpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// 关闭连接
connection.disconnect();
// 关闭进程
p.destroy();
}
一运行到converter.convert(inputFile, outputFile); 就出问题,求大神解惑
...全文
736 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
咖啡色的笑 2019-11-14
  • 打赏
  • 举报
回复
怎么另存的?
ZJJG4 2019-07-26
  • 打赏
  • 举报
回复
找到原因了,方法没问题,是因为我的word文件本质上是个html文件,根本不是word文档,另存为之后就能用了

10,606

社区成员

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

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