通过openOffice将office文件转成pdf
时间:2021-09-18 08:13:25|栏目:JAVA代码|点击: 次
下载安装openoffice,下载地址:http://www.openoffice.org/download/我安装的目录:

输入cmd回车

在命令窗口输入
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" ?Cnofirststartwizard
此时服务就开启了将以下代码放到工具类里面,直接调用即可
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
...
...
public File office2Pdf(String srcPath, String pdfPath) throws Exception {
// 源文件目录
File inputFile = new File(srcPath);
if (!inputFile.exists()) {
throw new Exception("程序出现问题,文件不存在");
}
// 输出文件目录
File outputFile = new File(pdfPath);
if (!outputFile.exists()) {
outputFile.createNewFile();
}
// 调用openoffice服务线程
String command = openOfficeCommand;
Process process = Runtime.getRuntime().exec(command);
// 连接openoffice服务
OpenOfficeConnection connection = new SocketOpenOfficeConnection(openOfficeUrl, openOfficePort);
connection.connect();
// 转换word到pdf
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// 关闭连接
connection.disconnect();
// 关闭进程
process.destroy();
return outputFile;
}
...
上一篇:以实例讲解Objective-C中的KVO与KVC机制
栏 目:JAVA代码
本文标题:通过openOffice将office文件转成pdf
本文地址:http://www.codeinn.net/misctech/175832.html


阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机




