前言
使用com.aspose.words中的方法把word转为pdf 的正式版的jar包是收费的。可以使用评估版,但评估版会在每个生成后的文档最上方插入评估字样的水印。

可以在网上搜一下破解版的,加上license.xml配置文件即可把水印去掉。
另外Aspose公司旗下有很全的一套office文档管理方案,公司设在澳大利亚。
公司差不多是专做各种文件格式处理插件的,产品系列挺多,有兴趣可以到官网上看看:
https://www.aspose.com/
一、需要导入的jar包
com.aspose.words 可网上找破解版jar 包然后在项目中引入
maven项目引入本地jar包教程
二、工具类代码
package com.test.api.utils;
import com.alibaba.fastjson.JSONObject;
import com.aspose.words.*;
import org.springframework.core.io.ClassPathResource;
import java.io.*;
/**
* @author Administrator
* @version $Id$
* @since
* @see
*/
public class Word2PdfUtil {
public static boolean getLicense() {
boolean result = false;
try {
// license.xml应放在..\WebRoot\WEB-INF\classes路径下
// InputStream is = Word2PdfUtil.class.getClassLoader().getResourceAsStream("license.xml");
ClassPathResource classPathResource = new ClassPathResource("license.xml");
InputStream is = classPathResource.getInputStream();
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void doc2pdf(String inPath, String outPath) {
if (!getLicense()) {
// 验证License 若不验证则转化出的pdf文档会有水印产生
return;
}
try {
File file = new File(outPath); // 新建一个空白pdf文档
FileOutputStream os = new FileOutputStream(file);
Document doc = new Document(inPath); // Address是将要被转化的word文档
// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,EPUB, XPS, SWF 相互转换
doc.save(os, SaveFormat.PDF);
os.close();
} catch (Exception e) {
e.printStackTrace(

本文介绍了如何使用com.aspose.words库将Word文档转换为PDF,包括如何处理评估版的水印问题,以及如何引入和验证license.xml来去除水印。此外,还提供了具体的Java代码示例和调用方法,涉及文件上传和转换流程。
工具类&spm=1001.2101.3001.5002&articleId=130492280&d=1&t=3&u=c5f3fb0a384d4225a89ed72a367bb625)
1978

被折叠的 条评论
为什么被折叠?



