和谐版jar包 加激活 去除水印 转换从此无限制 就算是在服务器上也不需要安装其他工具 目前最好 使用 方便快捷 jar包下载地址 链接: https://pan.baidu.com/s/1tlbueAQq5bxPNgncS7GgoA 提取码: p35p
/**
* word to pdf
* @param inPath word 全路径
* @param outPath 生成的pdf 全路径
* @author an
* @throws Exception
*/
public static String docPdf(String inPath, String outPath) {
if (!isWordLicense()) {
return null;
}
try {
String path = outPath.substring(0, outPath.lastIndexOf(File.separator));
File file = null;
file = new File(path);
if (!file.exists()) {//创建文件夹
file.mkdirs();
}
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,
} catch (Exception e) {
e.printStackTrace();
}
// EPUB, XPS, SWF 相互转换
return outPath;
}
/**
* @Description: 验证aspose.word组件是否授权:无授权的文件有水印和试用标记
*/
public static boolean isWordLicense() {
boolean result = false;
try {
// InputStream inputStream = new
// FileInputStream("D:\\Workspaces\\TestFilters\\lib\\license.xml");
// 避免文件遗漏
String licensexml = "<License>\n" + "<Data>\n" + "<Products>\n"
+ "<Product>Aspose.Total for Java</Product>\n" + "<Product>Aspose.Words for Java</Product>\n"
+ "</Products>\n" + "<EditionType>Enterprise</EditionType>\n"
+ "<SubscriptionExpiry>20991231</SubscriptionExpiry>\n"
+ "<LicenseExpiry>20991231</LicenseExpiry>\n"
+ "<SerialNumber>23dcc79f-44ec-4a23-be3a-03c1632404e9</SerialNumber>\n" + "</Data>\n"
+ "<Signature>\n"
+ "sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=\n"
+ "</Signature>\n" + "</License>";
InputStream inputStream = new ByteArrayInputStream(licensexml.getBytes());
com.aspose.words.License license = new com.aspose.words.License();
license.setLicense(inputStream);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
// outputStream转inputStream
public static ByteArrayInputStream parse(OutputStream out) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos = (ByteArrayOutputStream) out;
ByteArrayInputStream swapStream = new ByteArrayInputStream(baos.toByteArray());
return swapStream;
}