OpenOffice的使用说明
来源:互联网 发布:fastcopy 网络拷贝 编辑:程序博客网 时间:2024/06/05 11:05
OpenOffice的使用说明
1. 概述
1.1 Java程序中可以利用OpenOffice,将办公文档(包括doc、docx、xls、xlsx等)转换为PDF格式的文档。由于PDF格式的文档可以达到在线预览的效果,而Office办公文档实现在线预览相对来说会比较麻烦,但曲线救国,通过文档格式的转换,从而也很容易地达到对Office办公文档实现在线预览的效果。
2. OpenOffice的安装
2.1 以Windows版本的OpenOffice安装为例,到OpenOffice官网下载最新版本的OpenOffice软件【[OpenOffice下载地址](http://www.openoffice.org/download/index.html】
2.2 下载完毕后进行安装,但需要记住软件的安装目录,如安装在D:/Program Files (x86)/OpenOffice 4,这个安装路径在文档格式转换的时候需要用到。
3. 文档格式转换
3.1 将Office文档转换为PDF格式的文档
/** * * @description:将Office格式的文档转换为PDF格式的文档 * @author huang.j * @date 2017年5月24日 上午11:44:03 * @param inputFilePath * */ public void convertWord2Pdf(String inputFilePath) { DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration(); // OpenOffice安装在本地环境的目录 String officeHome = "D:/Program Files (x86)/OpenOffice 4"; config.setOfficeHome(officeHome); OfficeManager officeManager = config.buildOfficeManager(); officeManager.start(); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); String outputFilePath = getReplaceFileAbsolutePath(inputFilePath, ".pdf"); File inputFile = new File(inputFilePath); if (inputFile.exists()) { File outputFile = new File(outputFilePath); if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } // 进行PDF格式的转换 converter.convert(inputFile, outputFile); } officeManager.stop(); }
3.2 更改文档后缀为指定的后缀名
/** * * @description:更改文档后缀为指定的后缀名 * @author huang.j * @date 2017年5月24日 上午11:44:20 * @param inputFilePath 输入文档的绝对路径 * @param replaceEndWith 指定的后缀名 * @return 返回替换指定后缀名的文档的绝对路径 * */ private String getReplaceFileAbsolutePath(String inputFilePath, String replaceEndWith) { String replaceFilePath = null; Pattern pattern = Pattern.compile("(\\.[a-zA-Z]+)"); Matcher matcher = pattern.matcher(inputFilePath); String endWith = null; if(matcher.find()) { endWith = matcher.group(1); } if(StringUtil.isEmpty(endWith)) { return null; } replaceFilePath = inputFilePath.replaceAll(endWith, replaceEndWith); return replaceFilePath; }
4. PDF文档的预览
4.1 完成PDF格式的转换后,下一步就可以进行PDF文件的预览
/** * * @description:预览PDF文件 * @author huang.j * @date 2017年5月23日 下午4:51:59 * @param attathFile * @param response * */ public void previewPdf(File attathFile, HttpServletResponse response) { response.setContentType("application/pdf"); try { if(attathFile.exists()) { DataOutputStream dataOutputStream = new DataOutputStream(response.getOutputStream()); DataInputStream dataInputStream = new DataInputStream(new FileInputStream(attathFile)); byte[] buffer = new byte[2048]; int len = buffer.length; while((len = dataInputStream.read(buffer, 0, len)) != -1) { dataOutputStream.write(buffer); dataOutputStream.flush(); } dataInputStream.close(); dataOutputStream.close(); } } catch (Exception e) { logger.error(e.getMessage(), e); } }
5. Office办公文档转换为PDF文档所需的jar包
1) commons-cli-xx.jar
2) commons-io-xx.jar
3) jodconverter-core-3.0-beta-4.jar
4) json-xxx.jar
5) juh-xx.jar
6) jurt-xx.jar
7) ridl-xx.jar
8) unoil-xx.jarJar包资源下载地址【点击连接】
阅读全文
0 0
- OpenOffice的使用说明
- openoffice的中文输入
- OpenOffice Writer的技巧
- 粗谈OpenOffice的架构
- 安装openoffice的方法
- sun 的openoffice使用手册
- 查看openoffice的版本号
- openOffice的使用
- Apache的OpenOffice
- openoffice转换的调用
- OpenOffice的安装
- openOffice的使用
- linux openoffice的安装
- OpenOffice
- OpenOffice
- OpenOffice
- openoffice增加字体的方法
- linux 中openOffice 的安装
- OPPO R7 获取Google Play权限
- php自带排序函数sort()和用自己用php实现的快速排序算法,速度比较。
- 常见异常分类及举例
- 读书笔记《Effective C++》条款34:区分接口继承和实现继承
- 数据结构--顺序表合并操作
- OpenOffice的使用说明
- java的参数传递机制
- 小功能:下拉框里为不同的7天,复选框里为旅游点,每一天可以选择多个旅游点,每一天已选择的点其他天不能选,切换下拉框,当天选择好的点为以勾选状态
- LeetCode (Decode Ways)
- Android开发之给TabLayout加上能消失的ToolBar
- java多线程-Atomic
- Android程序猿带你学python第0章--导读
- 【POJ2429】GCD & LCM Inverse-Pollard-rho分解+枚举
- Springmvc 并发访问的线程安全性问题