word转pdf aspose.words去水印版
word转pdf aspose.words去水印版
备注:
1.工具类大同小异,都长一样,测试能用即可。记录一下,方便以后查阅
2.LogPrintUtil为自己封装的日志打印工具类,找不到无视、删除即可
3. 附破解jar!aspose.words为收费版,maven中央库找不到jar,jar为大牛反编译修改之后再编译成jar,想用直接引用或者deploy到私服仓库即可
4.License文件jar里已存在,/com.aspose.words.lic_2999.xml 路径无需改变用就可以了
5.测试专用,商业用途请购买正版!!!!!你懂得。
Util Class
package com.xxx.xxx.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
/**
* @author Administrator
* @version $Id$
* @since
* @see
*/
public class Word2PdfUtil {
/*
* public static void main(String[] args) { doc2pdf("E:/sms.docx","E:/aa.pdf");
* }
*/
public static boolean getLicense() {
boolean result = false;
try {
InputStream is = com.aspose.words.Document.class.getResourceAsStream("/com.aspose.words.lic_2999.xml");
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
LogPrintUtil.printErrorLog("reqId", "Word2PdfUtil", "getLicense", "转pdf报错", e);
}
return result;
}
public static void doc2pdf(String inPath, String outPath) {
if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
return;
}
try {
Long old = System.currentTimeMillis();
File file = new File(outPath); // 新建一个空白pdf文档
FileOutputStream os = new FileOutputStream(file);
Document doc = new Document(inPath); // Address是将要被转化的word文档
doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,
// EPUB, XPS, SWF 相互转换
Long now = System.currentTimeMillis();
LogPrintUtil.printFreeLog("reqId", "Word2PdfUtil", "doc2pdf", "转pdf成功耗时", (now - old) + "ms");
} catch (Exception e) {
LogPrintUtil.printErrorLog("reqId", "Word2PdfUtil", "doc2pdf", "转pdf报错", e);
}
}
}