社区
Java EE
帖子详情
win环境下openoffice将word转换成PDF后,和原word格式不符
山那边的路
2016-02-23 05:59:47
如题,我用Java代码利用openoffice将word2003 转换成PDF后 PDF的内容格式和原word的不符。如图
这是PDF的 ,
这是原word 这个明显出现不同 请教 怎么能让2个格式相符
...全文
1240
8
打赏
收藏
win环境下openoffice将word转换成PDF后,和原word格式不符
如题,我用Java代码利用openoffice将word2003 转换成PDF后 PDF的内容格式和原word的不符。如图 这是PDF的 ,这是原word 这个明显出现不同 请教 怎么能让2个格式相符
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
8 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
Dazer007
2017-09-04
打赏
举报
回复
楼主求分享您的经验。
Dazer007
2017-09-04
打赏
举报
回复
楼主解决了,这个问题。
qq_16462963
2016-11-14
打赏
举报
回复
楼主,这个问题解决了嘛,,可以分享一下吗
yongwenxiu
2016-09-02
打赏
举报
回复
解决了吗,现在我也遇到这样的问题
xiashany
2016-09-02
打赏
举报
回复
如果还不行的话就poi了
xiashany
2016-09-02
打赏
举报
回复
用LibreOffice吧,就是把这个按openoffice一样的处理
不写代码的钦
2016-09-02
打赏
举报
回复
两个不同的软件没办法的,在windows下用poi转吧
山那边的路
2016-02-24
打赏
举报
回复
不能沉了
Apache_
OpenOffice
_4转
pdf
支持将 .doc|.docx|.xls|.xlsx|.ppt|.pptx文件 转化为
pdf
文件 linux安装包: Apache_
OpenOffice
_4.1.2_Linux_x86_install-rpm_zh-CN.tar.gz Apache_
OpenOffice
_4.1.7_Linux_x86-64_install-rpm_zh-CN.tar.gz
win
dows安装包: Apache_
OpenOffice
_4.1.4_
Win
_x86_install_zh-CN.exe Apache_
OpenOffice
_4.1.7_
Win
_x86_install_zh-CN.exe
word
,ppt转
pdf
可以将
word
,ppt
转换成
pdf
格式
, 1.安装《Apache_
OpenOffice
_4.1.5_
Win
_x86_install_zh-CN.exe》 2.将jar包加入到工程中 3.编写Java类,注意配置安装的位置 package com.han.office; import java.io.File; import java.util.Date; import java.util.regex.Pattern; import org.artofsolving.jodconverter.OfficeDocumentConverter; import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; import org.artofsolving.jodconverter.office.OfficeManager; import com.sun.star.util.FileIOException; /** * 这是一个工具类,主要是为了使Office2003-2007全部
格式
的文档(.doc|.docx|.ppt|.pptx) * 转化为
pdf
文件
* @date 2018-1-18 * @author hanshaobin * */ public class Officer { public static void main(String[] args) { Officer office2
pdf
= new Officer(); try { office2
pdf
.office2
pdf
("d:/test.doc", "d:/java_" + new Date().getTime() + ".
pdf
"); office2
pdf
.office2
pdf
("d:/test.pptx"); } catch (FileIOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 使Office2003-2007全部
格式
的文档(.doc|.docx|.ppt|.pptx) 转化为
pdf
文件
* * @param inputFilePath * 源文件路径,如:"d:/test.docx" * @param outputFilePath * 目标文件路径,如:"d:/test_docx.
pdf
" * @return * @throws FileIOException * 文件
格式
不正确 */ public boolean office2
pdf
(String inputFilePath, String outputFilePath) throws FileIOException { if(!isRigthFileFix(inputFilePath)){ throw new FileIOException("文件
格式
不正确"); } boolean flag = false; OfficeManager officeManager = getOfficeManager(); // 连接
OpenOffice
OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); // long begin_time = new Date().getTime(); // 判断目标文件路径是否为空 if (null == outputFilePath) { // 转换后的文件路径 outputFilePath = getOutputFilePath(inputFilePath); } try{ converterFile(inputFilePath, outputFilePath, converter); flag = true; }catch(Exception e){ e.printStackTrace(); } officeManager.stop(); // long end_time = new Date().getTime(); // System.out.println("文件转换耗时:[" + (end_time - begin_time) / 1000 + "]s"); return flag; } /** * 使Office2003-2007全部
格式
的文档(.doc|.docx|.ppt|.pptx) 转化为
pdf
文件
* 默认转换位置与源文件位置相同,文件名相同 * @param inputFilePath * 源文件路径,如:"d:/test.docx" * @return * @throws FileIOException * 文件
格式
不正确 */ public boolean office2
pdf
(String inputFilePath) throws FileIOException { return office2
pdf
(inputFilePath, null); } /** * 根据操作系统的名称,获取
OpenOffice
4的安装目录
* 如我的
OpenOffice
4安装在:C:\\Program Files (x86)\\
OpenOffice
4
* @return
OpenOffice
4的安装目录 */ public String getOfficeHome() { String osName = System.getProperty("os.name"); if (Pattern.matches("Linux.*", osName)) { return "/opt/
openoffice
.org4"; } else if (Pattern.matches("
Win
dows.*", osName)) { return "C:\\Program Files (x86)\\
OpenOffice
4"; } else if (Pattern.matches("Mac.*", osName)) { return "/Application/
OpenOffice
.org.app/Contents"; } return null; } /** * 连接
OpenOffice
并且启动
OpenOffice
* @return */ public OfficeManager getOfficeManager() { DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration(); // 获取
OpenOffice
4的安装目录 String officeHome = getOfficeHome(); config.setOfficeHome(officeHome); // 设置超时时间为5分钟 config.setTaskExecutionTimeout(1000 * 60 * 5L); // 启动
OpenOffice
的服务 OfficeManager officeManager = config.buildOfficeManager(); officeManager.start(); return officeManager; } /** * 转换文件 * @param inputFilePath * 转换文件的路径及名称,例如:d:/test.doc * @param outputFilePath * 目标文件的路径及名称,例如:d:/test.
pdf
* @param converter */ public void converterFile(String inputFilePath, String outputFilePath, OfficeDocumentConverter converter) { File inputFile = new File(inputFilePath); File outputFile = new File(outputFilePath); // 假如目标路径不存在,则新建该路径 if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } // 文件转换 converter.convert(inputFile, outputFile); } /** * 获取输出文件 * @param inputFilePath * 输入文件的位置及文件名称,如:"d:/test.docx" * @return * 默认的输出文件路径:如:"d:/test.
pdf
" */ public String getOutputFilePath(String inputFilePath) { String outputFilePath = inputFilePath.substring(0,inputFilePath.lastIndexOf('.'))+".
pdf
"; return outputFilePath; } /** * 获取inputFilePath的后缀名,如:"d:/test.pptx"的后缀名为:"pptx"
* * @param inputFilePath * @return */ public String getPostfix(String inputFilePath) { return inputFilePath.substring(inputFilePath.lastIndexOf(".") + 1); } /** * 检查文件是否是指定
格式
* @param inputFilePath * 输入文件的路径 * @return * 是指定
格式
返回true ,否则返回 false */ public boolean isRigthFileFix(String inputFilePath){ String[] fixes =new String[]{"doc","docx","ppt","pptx"}; boolean flag = false; String fix = getPostfix(inputFilePath); for (String f : fixes) { if(f.equalsIgnoreCase(fix)){ flag = true; break; } } return flag; } } 工具下载位置:https://pan.baidu.com/s/1brhhbdH
Apache_
OpenOffice
_4.1.5_
Win
_x86_install_zh-CN.zip
OpenOffice
开源文档办公软件,可与Java集成实现
Word
、Excel、PPT
转换成
PDF
。在WEB项目利用这一技术主要实现文档在线预览。
java实现浏览器在线预览offic(doc、xls、ppt)和
pdf
文件
java实现浏览器在线预览offic(doc、xls、ppt)和
pdf
文件,本人将例子集成到项目中,已成功。 技术
原
理:将文件先
转换成
pdf
文件,再将
pdf
文件
转换成
swf文件,最后显示在浏览器上。 资源描述:本资源包括swftools安装包以及例子源码,由于
openOffice
太大,请大家去官网下载apache_
openoffice
_incubating_
win
_x86_install_zh-cn.zip。运行
环境
为
win
dows,若需运行在linux,请去官网下载对应版本。 说明:例子运行之前,请先修改代码中swftools安装路径,以及文件存放路径。
word
完美转换
pdf
需要下载Apache_
OpenOffice
_4.1.1_
Win
_x86_install_zh-CN,步骤有txt写好了,下载直接导入程序就可以了
Java EE
67,513
社区成员
225,879
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章