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

相关推荐
正在走向自律7 小时前
实战心得:利用PaddleOCR彻底解决大模型无法解析图片型PDF的问题
开发语言·pdf·视觉检测·paddleocr·视觉模型·离线ocr识别
AI原来如此7 小时前
零基础教程:50页PDF一键浓缩成1页摘要
人工智能·ai·pdf·大模型
186******205317 小时前
PDF 转 Word 高效办公实战指南
pdf·word
随手工具-Excel, pdf, SQL7 小时前
PDF删除页面怎么操作?免费在线删除PDF指定页面,无需安装软件
pdf
SunnyDays101119 小时前
Java 实现 PDF 页面删除、排序、旋转和裁剪
java·pdf
zyplayer-doc1 天前
个人 AI 知识库怎么搭建:用 zyplayer-doc 把笔记、PDF 和图片资料变成可问答的第二大脑
大数据·开发语言·人工智能·笔记·pdf·ocr
patrickpdx1 天前
Word批量修改指定字符的字体
word·word2016
日日行不惧千万里1 天前
Java AI 完整学习笔记
pdf
听风吹等浪起2 天前
002:多图合并导出PDF【网页版】
计算机视觉·pdf
蝶恋舞者2 天前
NMC-G2网络管理卡 资料官网下载流程
pdf