- 實作功能
- docx檔案轉換為PDF
- 轉換之后排版不混亂
- 依賴
- aspose-words-15.8.0-jdk16.jar包提取路徑(用于PDF轉換 )
鏈接:https://pan.baidu.com/s/1myCbpT7_H8MXY-oQD10S4Q
提取碼:yxzs
- aspose-words-15.8.0-jdk16.jar包提取路徑(用于PDF轉換 )
- 環境
- JDK1.8
- 代碼
import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
/**
* @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");
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 {
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();
System.out.println("共耗時:" + ((now - old) / 1000.0) + "秒"); // 轉化用時
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
- 下面是配置的xml檔案 直接復制黏貼即可
<?xml version="1.0" encoding="UTF-8" ?>
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
<Product>Aspose.Words 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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/139767.html
標籤:其他
上一篇:bool型別在VS中引發的血案
下一篇:直播一對一視頻直播聊天
