将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包可以在我资源库下载

相关推荐
喝凉白开都长肉的大胖子1 天前
比较 main.tex 的两个不同版本(例如旧版和新版),并生成一个带有修改标记(如删除线、高亮、修订注释)的 PDF 或文本输出。
pdf·latex
_处女座程序员的日常1 天前
如何预览常见格式word、excel、ppt、图片等格式的文档
前端·javascript·word·excel·开源软件
weixin_441003641 天前
2025教资面试真题电子版|科目试讲+结构化真题解析|完整PDF
面试·职场和发展·pdf
小兜全糖(xdqt)1 天前
python ppt转pdf以及图片提取
python·pdf·powerpoint
番石榴AI1 天前
视频转ppt/pdf V2.0版(新增转为可编辑PPT功能)
人工智能·pdf·powerpoint
_深巷的猫1 天前
python爬虫自动库DrissionPage保存网页快照mhtml/pdf/全局截图/打印机另存pdf
pdf
『 时光荏苒 』1 天前
网页变成PDF下载到本地
前端·javascript·pdf·网页下载成
chenchihwen1 天前
AI代码开发宝库系列:PDF文档解析MinerU
人工智能·python·pdf·dashscope
Source.Liu2 天前
【PDF-rs】pdf子项目的lib.rs文件
pdf
学会用脚编程2 天前
word转Pdf,在window正常,放在linux服务器上就转出来中文是空白
pdf·word