openoffice转pdf
来源:互联网 发布:淘宝u站特价乐购 编辑:程序博客网 时间:2024/06/06 15:51
文章来自:http://blog.csdn.net/youthon/article/details/32717471
1. 需要用的软件
OpenOffice 下载地址http://www.openoffice.org/
JodConverter 下载地址http://sourceforge.net/projects/jodconverter/files/JODConverter/,也可以直接从附件里面下载
2.启动OpenOffice的服务
安装完openoffice,安装服务
cd C:\Program Files (x86)\OpenOffice 4\program
执行
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
查看是否安装成功,查看端口对应的pid
netstat -ano|findstr "8100"
查看pid对应的服务程序名
tasklist|findstr "pid值"
3.将JodConverter相关的jar包添加到项目中
4. 下面是实现代码
附件里面有现成的可以用的项目示例,直接导入eclipse就可以运行
- /**
- * 将Office文档转换为PDF. 运行该函数需要用到OpenOffice, OpenOffice下载地址为
- * http://www.openoffice.org/
- *
- * <pre>
- * 方法示例:
- * String sourcePath = "F:\\office\\source.doc";
- * String destFile = "F:\\pdf\\dest.pdf";
- * Converter.office2PDF(sourcePath, destFile);
- * </pre>
- *
- * @param sourceFile
- * 源文件, 绝对路径. 可以是Office2003-2007全部格式的文档, Office2010的没测试. 包括.doc,
- * .docx, .xls, .xlsx, .ppt, .pptx等. 示例: F:\\office\\source.doc
- * @param destFile
- * 目标文件. 绝对路径. 示例: F:\\pdf\\dest.pdf
- * @return 操作成功与否的提示信息. 如果返回 -1, 表示找不到源文件, 或url.properties配置错误; 如果返回 0,
- * 则表示操作成功; 返回1, 则表示转换失败
- */
- public static int office2PDF(String sourceFile, String destFile) {
- 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 (FileNotFoundException e) {
- e.printStackTrace();
- return -1;
- } catch (ConnectException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return 1;
- }
0 0
- openoffice转pdf错误
- openoffice转pdf
- openoffice doc转pdf优化
- liunx 下java通过openoffice转pdf
- Java项目中使用OpenOffice转PDF
- PHP调用OpenOffice实现word转PDF
- openoffice java实现word转PDF
- 通过OpenOffice转换PDF
- 通过OpenOffice转换PDF
- openOffice服务html转PDF中文乱码问题
- openOffice实现word转pdf和添加水印
- java调用Apache OpenOffice实现TXT、HTML、OFFICE转PDF
- Java实现各种文件转PDF(使用OpenOffice)
- OpenOffice 转换pdf->图片 代码
- word 上传后转pdf,pdf又转swf,工具openoffice和pdf2swf.exe
- openOffice+pdf2swf类百度文库):pdf转swf(Linux,window)
- openOffice+pdf2swf+flexpaper(类百度文库) :office转pdf(Linux,window)
- openOffice+pdf2swf+flexpaper(类百度文库) :office转pdf(Linux,window)
- 水晶报表中使用条码字体
- 创建podfile 文件
- DB2常用操作
- Java 课堂笔记
- 我是测试文章
- openoffice转pdf
- Unity3d多人游戏与网络功能(四)-状态机同步与远程动作
- 网址收藏
- post请求错误net::ERR_CONNECTION_RESET解决
- MySQL:索引工作原理及索引的用法
- MangoDB learning
- CodeForces 631A-Interview
- UDP java接受数据与发送数据
- Android中 android:layout_weight 属性 完美解释