package test; import java.io.File; import java.util.regex.Pattern; import org.artofsolving.jodconverter.OfficeDocumentConverter; import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; import org.artofsolving.jodconverter.office.OfficeManager; public class WordToPdf { /** * 将Office文档转换为PDF. 运行该函数需要用到OpenOffice, OpenOffice * * @param sourceFile * 源文件,绝对路径. 可以是Office2003-2007全部格式的文档, Office2010的没测试. 包括.doc, .docx, .xls, .xlsx, .ppt, .pptx等. * * @param destFile * 目标文件.绝对路径. */ public static void word2pdf(String inputFilePath) { DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration(); String officeHome = getOfficeHome(); System.out.println("获取openOffice安装主目录"+officeHome); config.setOfficeHome(officeHome); OfficeManager officeManager = config.buildOfficeManager(); officeManager.start(); System.out.println("开启openOffice服务"); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); String outputFilePath = getOutputFilePath(inputFilePath); File inputFile = new File(inputFilePath); if (inputFile.exists()) {// 找不到源文件, 则返回 File outputFile = new File(outputFilePath); if (!outputFile.getParentFile().exists()) { // 假如目标路径不存在, 则新建该路径 outputFile.getParentFile().mkdirs(); } converter.convert(inputFile, outputFile); } officeManager.stop(); System.out.println("关闭openOffice服务"); System.out.println("WORD成功转换为PDF"); } public static String getOutputFilePath(String inputFilePath) { String outputFilePath = inputFilePath.replaceAll(".doc", ".pdf"); return outputFilePath; } public static String getOfficeHome() { String osName = System.getProperty("os.name"); if (Pattern.matches("Linux.*", osName)) { return "/opt/openoffice.org3"; } else if (Pattern.matches("Windows.*", osName)) { return "C:/Program Files/OpenOffice.org 3"; } else if (Pattern.matches("Mac.*", osName)) { return "/Application/OpenOffice.org.app/Contents"; } return null; } public static void main(String[] args) { word2pdf("D:/XX系统需求分析文档.doc"); } }
相关推荐
word 转换为pdf进行预览,在线预览word文档,word文档通过wps接口转换为pdf,C# word文档通过wps接口转换为pdf;引用的第三方dll 属性必须设置为可复制!!!
用C#.NET实现生成PDF文档和将WORD转换为PDF
将word转换为pdf等格式,该jar为已破解的jar,仅限于学习,非商业用途,存在问题可联系博主,博主会细心帮助解决!
VS2010写的将Word转换成PDF的例子,例子页面为About.aspx,服务器需要安装Office2010
word转换为pdf工具
python实现excel、word转换为pdf
VBA程序将Word转成PDF,可以做出WSF供Java和C程序调用。此程序调通过,实际项目上用到过,仅供参考。
1、 Word转换为Pdf,程序很多,但转换后的Pdf,还可以复制,虽可以加密禁止复制,但市场上太多的Pdf,还可以把Pdf转换Word等其他格式,很容易被别人利用和剽窃,如何彻底的自己的Word文档,可以被人浏览,查看,而不...
VS2010写的将Word转换成PDF的例子,例子页面为About.aspx,服务器需要安装Office2010
此jar为18.11版本,java将word转换为pdf,无需使用office组件,详细破解过程请看博客。
WORD转换为PDF工具,很好用的,相当绿色
Word转换成PDF转换器为Word文档转换成Adobe PDF最完整的解决方案。 Word转换成PDF转换器能批量转换微软办公软件格式到PDF, 节省时间, 同时支持多核CPU,让你转换的过程中更快捷更有效。 Word转换成PDF转换器可以...
使用aspose.word将word文档转换成pdf格式,核心代码: Document doc = new Document(wordFolderPath); doc.Save(pdfFolderPath, SaveFormat.Pdf); 本程序实现了将制定word文件转换成pdf格式,或者制定文件夹,将...
网上将word转换为pdf方法很多,但似乎操作起来很麻烦,现提供简单的方法!
本软件可以将word或ppt文件轻松转换为pdf格式
此软件能将WORD转换成PDF的软件,非常实用
可以在linux中将word转为pdf,通过java代码实现,简单无脑操作,好用简单,只需要引入jar包即可,命令,代码,jar包全部都在。
可以实现doc和docx文档转成pdf,不含水印,转换后的pdf文件比较清晰,感兴趣的朋友可以尝试一下
word转pdf(pdftoword)工具是一款功能强大好用的word转pdf软件工具,在1.3版本中新增加了pdf转word的功能,可以实现pdf与word的相互转换,界面简单,功能稳定,支持批量转换,操作起来非常方便,支持多种流行文档...