Aspose.Java实现word转pdf,添加水印等操作
Aspose是一款商用版控件,支持各类文档操作,这里主要介绍如何在Springboot项目中使用破解版。
一. word转pdf
- 在项目中导入aspose.word包 百度网盘下载 提取码:pokb
- 新建一个asposeUtil类,类中建立如下静态方法
/**
* @param wordPath 需要被转换的word全路径带文件名
* @param pdfPath 转换之后pdf的全路径带文件名
*/
public static void doc2pdf(String wordPath, String pdfPath) {
if (!getLicense()) {
// 验证License 若不验证则转化出的pdf文档会有水印产生
return;
}
try {
long old = System.currentTimeMillis();
File file = new File(pdfPath); //新建一个pdf文档
FileOutputStream os = new FileOutputStream(file);
Document doc = new Document(wordPath); //Address是将要被转化的word文档
doc.save(os, com.aspose.words.SaveFormat.PDF);
long now = System.currentTimeMillis();
os.close();
// System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒"); //转化用时
} catch (Exception e) {
e.printStackTrace();
}
}
- 新建license.xml文件(放入Springboot项目的resources目录下)
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
<Product>Aspose.Words for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>