java代码实现word转PDF
来源:互联网 发布:八爪鱼淘宝营销大师 编辑:程序博客网 时间:2024/05/20 04:48
本次实现是用openoffice的插件实现的
jar包:
commons-io-1.4.jar
jodconverter-2.2.1.jar
juh.jar
jurt.jar
ridl-3.2.1.jar
slf4j-api-1.7.7.jar
unoil.jar
以上jar包会在百度云提供
l链接:http://pan.baidu.com/s/1kUTYLtd
密码:in71
代码:
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;
}
}
- java代码实现word转PDF
- word转pdf(java实现)
- java实现word转pdf
- java 实现word转pdf
- word转pdf代码
- java实现word,ppt,excel转pdf
- Word转PDF(Java实现)
- Word转PDF(Java实现)
- java实现word转pdf-附全码
- openoffice java实现word转PDF
- Java Word转Pdf
- Java Word 转 Pdf
- java word转pdf
- java word转pdf
- java-pdf转word
- Java Word 转 Pdf
- java:word转pdf
- Jacob实现word转pdf
- vertical-align的垂直居中 上标下标 及line-height
- ORA-00933: SQL 命令未正确结束
- Bootstrap标签Tabs中使用focus
- 不要把BPM单纯的看做一般的项目
- 视图函数
- java代码实现word转PDF
- 一只兔子帮你理解KNN
- Python中使用item()方法遍历字典的例子
- android中extends 和implements的区别
- 关于红配绿的看法
- Spring配置文件详解
- 快速删除表数据,
- 2017-11-2 Linux磁盘管理
- java类和类中的变量、方法默认权限修饰符的用法