将word转为PDF的几种简单方式

第一种:使用spire.doc.jar包,用时7秒左右。

引入spire.doc-11.1.1.jar包,该包带水印,建议使用免费版的spire.doc.free-5.2.0.jar,免费版只能转三页。

package web.tools.excel;

import com.spire.doc.*;

public class test {

public static void main(String[] args) {

Document doc = new Document();

doc.loadFromFile("D:/Backup/Downloads/我的源文件.docx");

doc.saveToFile("D:/Backup/Downloads/输出文件.pdf", FileFormat.PDF);

doc.close();

System.out.println("转化完毕-----------------------");

}

}

第二种:使用aspose-words-15.8.0-jdk16.jar包,用时3秒左右。

/**

* 将word文档转为PDF后输出

* 烟雨江南

* @param urlIn word文档所在全路径 ;dir输出文档的目录

* @return

*/

public static String wordToPdf(String urlIn,String dir){

String url="";

try {

//自定义新文件名

SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd-HH-mm");

long dateTime = new Date().getTime();

String currentTimestr = sdf1.format(dateTime);

String newFileName = currentTimestr + "-" + suiJishu() + ".pdf";

url=dir+"/"+newFileName;

//

String s = "<License><Data><Products><Product>Aspose.Total for Java</Product>

ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());

License license = new License();

license.setLicense(is);

com.aspose.words.Document document = new com.aspose.words.Document(urlIn);

File file=new File(url);

FileOutputStream out=new FileOutputStream(file);

document.save(out,SaveFormat.PDF);

out.close();

} catch (Exception e) {

e.printStackTrace();

}

return url;

}

备注:jar包可以在我资源库下载

相关推荐
开开心心_Every1 小时前
剪切板工具存500条,可搜索备份导入导出
linux·运维·服务器·华为od·edge·pdf·华为云
疯狂敲代码的老刘5 小时前
PDFSam Basic:轻量开源的 PDF 拆分合并利器
pdf·工具·pdf工具·pdfsam
开开心心_Every1 天前
在线看报软件, 22家知名报刊免费看
linux·运维·服务器·华为od·edge·pdf·华为云
开开心心就好1 天前
轻松加密文件生成exe,无需原程序解密
linux·运维·服务器·windows·pdf·harmonyos·1024程序员节
我在这里呀1 天前
免费在线PDF翻译工具(保留排版,可导出Word)
pdf·word
❀͜͡傀儡师1 天前
Vue+SpringBoot 集成 PageOffice实现在线编辑 Word、Excel 文档
vue.js·spring boot·word
软件工程小施同学1 天前
区块链论文速读 CCF A--VLDB 2025 (2) 附pdf下载
pdf·区块链
❀͜͡傀儡师1 天前
Spring Boot 实现PDF水印的完整指南
spring boot·后端·pdf
weixin_449173652 天前
java使用poi保存表格和图片到word文件中
java·开发语言·word
大黄说说2 天前
Python 实战指南:一键批量旋转 PDF 页面方向
开发语言·python·pdf