转自:

https://www.cnblogs.com/qiwu1314/p/6101400.html

 

demo:

 

 

 

public class Doc2Pdf {
public static boolean getLicense(){
boolean result = false;
try{

InputStream is = Doc2Pdf.class.getClassLoader().getResourceAsStream("license.xml");
License license = new License();
license.setLicense(is);
return true;
}catch (Exception e){
e.printStackTrace();
return false;
}
}

public static void doc2pfd(String address){

if(!getLicense()){
System.out.println("license结果:false" );
return;
}
try{
long old = System.currentTimeMillis();
File file = new File("E:/test/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 相互转换
long now = System.currentTimeMillis();
System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒"); //转化用时
}catch (Exception e){

}
}

public static void main(String[] args) {
Doc2Pdf.doc2pfd("E:/test/test.docx");
}
}

<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>23dcc79f-44ec-4a23-be3a-03c1632404e9</SerialNumber>
</Data>
<Signature>0nRuwNEddXwLfXB7pw66G71MS93gW8mNzJ7vuh3Sf4VAEOBfpxtHLCotymv1PoeukxYe31K441Ivq0Pkvx1yZZG4O1KCv3Omdbs7uqzUB4xXHlOub4VsTODzDJ5MWHqlRCB1HHcGjlyT2sVGiovLt0Grvqw5+QXBuinoBY0suX0=</Signature>
</License>



posted on 2019-09-23 17:36  毛会懂  阅读(387)  评论(0编辑  收藏  举报