資源包:https://download.csdn.net/download/qq_36598111/90787167
jar包是破解過的,直接可以使用。
引入jar,要引入本地的,不要直接引入倉庫的
<dependency><groupId>com.aspose</groupId><artifactId>aspose-words</artifactId><version>18.6</version></dependency>
然后把license.xml 放在resourseces下面
直接使用就可以,注意要先驗證之后才能轉換
import java.io.*;import com.aspose.words.*;public class DocToPdf {public static boolean getLicense() {boolean result = false;try {InputStream is = DocToPdf.class.getClassLoader().getResourceAsStream("license.xml"); // license.xml應放在..\WebRoot\WEB-INF\classes路徑下License aposeLic = new License();aposeLic.setLicense(is);result = true;} catch (Exception e) {e.printStackTrace();}return result;}public static void doc2pdf(String Address, 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(Address); // Address是將要被轉化的word文檔doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML,} catch (Exception e) {e.printStackTrace();}}public static void main(String[] args) {doc2pdf("D:/123.doc", "D:/1234.pdf");}}