详细解决方案
openoffice 装配 以及结合jodconverter
热度:333 发布时间:2016-05-05 05:54:45.0
由于最近项目用到了 openoffice 进行文件类型的转换。
进行了初步的学习。
软件要求
1.openoffice 目前最新版本是OpenOffice.org 3.4.1。 3.3以下的都含有jar的下载。
3.4就不含有了。官方网址:http://www.openoffice.org/download/other.html#tested-sdk
2.用于调用openoffice的第三方插件 jodconverter 目前最新版本
jodconverter-core-3.0-beta-4-dist
官网地址:http://code.google.com/p/jodconverter/
使用步骤:
openoffice 双击安装后。
在命令行输入如下命令:
cd C:\Program Files\OpenOffice.org 3\program
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;"
-nofirststartwizard
port 可以更改避免更其他端口冲突。命令输入后 就启动了openoffice服务。
下面是封装的 fileutil
import java.io.File;import java.io.IOException;import org.apache.tomcat.util.http.fileupload.FileUtils;import org.artofsolving.jodconverter.OfficeDocumentConverter;import org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration;import org.artofsolving.jodconverter.office.OfficeManager;import org.icepdf.core.exceptions.PDFException;import org.icepdf.core.exceptions.PDFSecurityException;public class FileUtil { private static OfficeManager officeManager; public static synchronized void initOpenOfficeManager(){ if(FileUtil.officeManager!=null) return; FileUtil.officeManager = new ExternalOfficeManagerConfiguration().buildOfficeManager(); FileUtil.officeManager.start(); } public static void destriyOpenOfficeManager(){ FileUtil.officeManager.stop(); } private static OfficeManager getOfficeManager(){ if(FileUtil.officeManager==null) FileUtil.initOpenOfficeManager(); return FileUtil.officeManager; } //根据文件路径清空其路径所在的文件夹中的所有文件 public static void cleanDirectory(String url) throws IOException{ File file = new File(url); if(!file.isDirectory()){ file = new File(url.substring(0, url.lastIndexOf("/"))); } if(file.exists()&&file.isDirectory()) FileUtils.cleanDirectory(file); } /** * office 文件转 PDF * @param input 源文件路径 * @param output 目标文件路径 * @return 是否生成成功 */ public static void office2PDF(String input,String output){ File inputFile = new File(input); File outputFile = new File(output); //OfficeManager officeManager = new ExternalOfficeManagerConfiguration().buildOfficeManager(); //officeManager.start(); OfficeDocumentConverter converter = new OfficeDocumentConverter(FileUtil.getOfficeManager()); converter.convert(inputFile,outputFile); //officeManager.stop(); } public static DocumentState getDocumentState(String filePath) throws PDFException, IOException, PDFSecurityException{ return FileUtil.getDocumentState(filePath,1.0f,0f,1); } public static DocumentState getDocumentState(String filePath,float zoom,float rotation,int pageCursor) throws PDFException, IOException, PDFSecurityException{ DocumentState state = new DocumentState(filePath,zoom,rotation,pageCursor); state.openDocument(); return state; }}
顺带介绍一下 有兴趣可以加入 openoffice的中文社区
http://forum.openoffice.org/zh/forum/viewforum.php?f=3
相关解决方案
- openoffice 转化 文档至 pdf 实施失败
- openoffice -轮换文本的宏
- openoffice -查寻文本并设置文本字体的宏
- openoffice -将文本写下到状态栏的宏
- OpenOffice java api UNO 课程
- openoffice 装配,启动,测试
- openoffice Persistent = true失效的有关问题
- openoffice 在目前光标位置插入批注的宏
- ubuntu 手工装配 OpenOffice 3.2
- OpenOffice 题目
- openoffice 变换各种文件
- lwxshow.com资源-Mac 上在office OpenOffice download 中文版,快速,迅雷下载
- Openoffice 安插html图片 并保存在文档中
- java openoffice word转pdf 装换报错,该怎么处理
- openoffice doc转PDF解决办法
- ajax 结合 后台线程 有关问题请问
- SSH 联接是否需要使用 Public Key 以及 authorized_keys
- openoffice doc转PDF,该怎么解决
- jsp中JSTL 结合 EL 的有关问题?
- jsp处理机制 以及 错误跳转有关问题
- J2ME 装配
- 对于 spring 结合 acegi 处理文件上传
- 请问struts2.1 中 <sx:datetimepicker>以及<s:token>的使用步骤
- 想 关于xml 的dome (包括数据的封装 以及 xml的解析)
- Eclipse Luna 装配 velocity插件
- [Eclips 装配] Eclipse 发行版本
- Myeclipse 装配 gradle 插件以及基本使用
- eclipse for mac 装配
- Ubuntu中Eclipse 装配
- 转-mac myeclipse10 装配