1.首先下载 ASPOSE - WORD jar包放在lib下
2.添加 license.xml文件
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
<Product>Aspose.Pdf for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SubscriptionExpiry>20991231</SubscriptionExpiry>
<LicenseExpiry>20991231</LicenseExpiry>
<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
</Data>
<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>
3.示例代码
package com.duor.aladdin.report.util;
import com.aspose.pdf.License;
import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;
import java.io.*;
public class AsposeWordsUtils {
private static InputStream license;
private static InputStream fileInput;
private static File outputFile;
/**
* 获取license
*
* @return
*/
public static boolean getLicense() {
boolean result = false;
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
license = new FileInputStream(loader.getResource("exportXml/license.xml").getPath());// 凭证文件
fileInput = new FileInputStream(loader.getResource("pdf/Report.pdf").getPath());// 待处理的文件
outputFile = new File("D:\\company\\develop\\aladdin2\\aladdin_report\\src\\main\\resources\\123.doc");// 输出路径
License aposeLic = new License();
aposeLic.setLicense(license);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
*
* @param args
*/
public static void main(String[] args) {
// 验证License
if (!getLicense()) {
return;
}
try {
long old = System.currentTimeMillis();
Document pdfDocument = new Document(fileInput);
OutputStream fileOutput = new FileOutputStream(outputFile);
pdfDocument.save(fileOutput, SaveFormat.DocX);
long now = System.currentTimeMillis();
System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒\n\n" + "文件保存在:" + outputFile.getPath());
} catch (Exception e) {
e.printStackTrace();
}
}
}
即可完美转换