package com.whyc.util; import com.aspose.words.Document; import com.aspose.words.SaveFormat; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Word2PdfAsposeUtil { /**去除水印专用*/ /*public static boolean getLicense() { boolean result = false; try { InputStream is = Test.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 boolean doc2pdf(String inPath, String outPath) { /*if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生 return false; }*/ FileOutputStream os = null; try { File file = new File(outPath); // 新建一个空白pdf文档 os = new FileOutputStream(file); Document doc = new Document(inPath); // Address是将要被转化的word文档 doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, } catch (Exception e) { e.printStackTrace(); return false; }finally { if (os != null) { try { os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; } }