你知道如何将Word文档转为PDF吗?

总所周知,PDF 文档不适合设计和编辑内容,但没有任何信息和外观损失,它们非常安全且易于从一个系统转移到另一个系统。另一方面,Microsoft Word 文档(.doc 文件)是最适合设计和编辑的文档。因此,创建 PDF 文档最流行的方法是在 MS Word 文档中设计和创建内容,然后将Word文件从Doc转换为 PDF

如何将文档转换为 PDF?

只需3个简单的步骤,您就可以使用Spire.PDFConverter完成Doc到PDF的整个转换过程。

第 1 步:安装并运行 Spire.PDFConverter

第 2 步:选择 Doc 文件

单击按钮“添加文件”以选择要转换的 Doc 文件。Spire.PDFConverter 支持批量转换,这意味着您可以添加多个 Doc 文件。

第 3 步:开始转换

选择输出文件夹并单击按钮“转换

Word转PDF就是这么简单! 赶快学起来吧~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以将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文件<br> * @date 2018-1-18 * @author hanshaobin * */ public class Officer { public static void main(String[] args) { Officer office2pdf = new Officer(); try { office2pdf.office2pdf("d:/test.doc", "d:/java_" + new Date().getTime() + ".pdf"); office2pdf.office2pdf("d:/test.pptx"); } catch (FileIOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 使Office2003-2007全部格式的文档(.doc|.docx|.ppt|.pptx) 转化为pdf文件<br> * * @param inputFilePath * 源文件路径,如:"d:/test.docx" * @param outputFilePath * 目标文件路径,如:"d:/test_docx.pdf" * @return * @throws FileIOException * 文件格式不正确 */ public boolean office2pdf(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文件<br> * 默认转换位置与源文件位置相同,文件名相同 * @param inputFilePath * 源文件路径,如:"d:/test.docx" * @return * @throws FileIOException * 文件格式不正确 */ public boolean office2pdf(String inputFilePath) throws FileIOException { return office2pdf(inputFilePath, null); } /** * 根据操作系统的名称,获取OpenOffice4的安装目录<br> * 如我的OpenOffice 4安装在:C:\\Program Files (x86)\\OpenOffice 4<br> * @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("Windows.*", 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"<br> * * @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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值