資源簡介
壓縮包里有三個aspose的jar包和java文件 我的是web項目 里面jar齊全 沒發現需要什么 但是如果運行報錯,請根據缺包提示加入相應jar包,還有注意license.xml文件路徑,親測可用,有問題可以留言
代碼片段和文件信息
package?com.jhq.web.util;
import?java.io.File;
import?java.io.FileOutputStream;
import?junit.framework.Test;
import?com.aspose.words.Document;
import?com.aspose.words.SaveFormat;
public?class?Word2Html?{
public?static?boolean?getLicense()?{???????
boolean?result?=?false;???????
try?{???????????
java.io.InputStream?is?=?Test.class.getClassLoader().getResourceAsStream(“license.xml“);?//??wordlicense.xml應放在..\WebRoot\WEB-INF\classes路徑下???????????
com.aspose.words.License?aposeLic?=?new?com.aspose.words.License();???????????
aposeLic.setLicense(is);???????????
?result?=?true;???????
?}
catch?(Exception?e)?{??????????????????????????
e.printStackTrace();???????
}???????
return?result;???
}??
public?static?void?word2pdf(String?Address)?{???????????????
?if?(!getLicense())?{??????????//?驗證License?若不驗證則轉化出的PDP文檔會有水印產生???????????
?return;???????
?}?
?try?{??????????????
File?file?=?new?File(“D:/pdf1.pdf“);??//新建一個空白pdf文檔???????????
FileOutputStream?os?=?new?FileOutputStream(file);???????????
Document?doc?=?new?Document(Address);????????????????????//Address是將要被轉化的word文檔???????????
doc.save(os?SaveFormat.PDF);????????????????????????????//全面支持DOC?DOCX?OOxml?RTF?HTML?OpenDocument?PDF?EPUB?XPS?SWF?相互轉換????????????os.close();???????
?}
?catch?(Exception?e)?{???????????
?e.printStackTrace();???????
?}????
}
public?static?void?main(String[]?args)?{
word2pdf(“D:/論文.doc“);
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-01-26?13:33??word轉pdf\
?????文件?????6062936??2018-01-20?16:24??word轉pdf\aspose-cells-8.5.2.jar
?????文件?????8543532??2018-01-20?16:24??word轉pdf\aspose-words-14.9.0-jdk16.jar
?????文件????????2998??2018-01-20?16:24??word轉pdf\aspose_license.jar
?????文件?????????584??2018-01-22?10:31??word轉pdf\license.xm
?????文件????????1609??2018-01-26?13:32??word轉pdf\Word2Html.java
評論
共有 條評論