openoffice java实现word转PDF
来源:互联网 发布:java html转义 编辑:程序博客网 时间:2024/05/16 12:42
看了网上好多实现word转PDF的文章,都是源码能找到,找不到所依赖的jar包 ,发表一个有jar包的demo.
附带下载openoffice的下载地址:http://www.openoffice.org/
package office2PDF;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
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 office2PDF {
public static void main(String[] args) {
Date startDate = new Date();
String sourceFile = "C:\\Users\\Ice\\Desktop\\aaa.doc";
String destFile = "C:\\Users\\Ice\\Desktop\\zrc.pdf";
try {
System.out.println(office2PDF(sourceFile, destFile));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Date endDate = new Date();
System.out.println("the cost time is "+(endDate.getTime()-startDate.getTime()));
}
public static int office2PDF(String sourceFile, String destFile) throws FileNotFoundException {
try {
File inputFile = new File(sourceFile);
if (!inputFile.exists()) {
return -1;// 找不到源文件, 则返回-1
}
// 如果目标路径不存在, 则新建该路径
File outputFile = new File(destFile);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(
"127.0.0.1", 8100);
connection.connect();
// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(
connection);
converter.convert(inputFile, outputFile);
// close the connection
connection.disconnect();
return 0;
} catch (ConnectException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return 1;
}
}
阅读全文
0 0
- openoffice java实现word转PDF
- PHP调用OpenOffice实现word转PDF
- openOffice实现word转pdf和添加水印
- JAVA OpenOffice+jodconverter转换WORD为PDF
- word转pdf(java实现)
- java实现word转pdf
- java 实现word转pdf
- java调用Apache OpenOffice实现TXT、HTML、OFFICE转PDF
- Java实现各种文件转PDF(使用OpenOffice)
- 求助:php 用windows COM组件调用openoffice接口实现word转pdf文件报错
- 将Office(如:Word、Excel、PPT 等)文件转PDF(通过OpenOffice实现)
- Java用OpenOffice将word转换为PDF
- Java用OpenOffice将word转换为PDF并预览
- liunx 下java通过openoffice转pdf
- Java项目中使用OpenOffice转PDF
- java实现word,ppt,excel转pdf
- Word转PDF(Java实现)
- Word转PDF(Java实现)
- Android(常用)主流UI开源库整理
- 6 OF 100DAYS
- Spring Boot 03 profile的使用
- MSP430定时/计数器TimerA的使用详解(一)
- make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] 错误 1 问题解决
- openoffice java实现word转PDF
- 统计学习方法 6-逻辑斯谛回归与最大熵模型
- 测试小故事44:客观
- bitTiger讲解:Leetcode如何刷(经验分享)
- [机器学习实战] Ubuntu 16.04 + NVIDIA 384 + OpenCV 3.1.0 + CUDA 8.0 + cuDNN 5.1 踩坑记录
- Prim和Kruskal求最小生成树
- 递归算法的时间复杂度分析
- 344. Reverse String
- Could not obtain transaction-synchronized Session for current thread