优先用 aspose-words-19.3.jar ,不需要读取license.xml,导出后直接水印,jar包最好直接放在项目resource目录下直接引用,要不下载不下来
public static String doc2pdf(String fileName, String filePath) {try {String oldFile = filePath + fileName;String newFile = oldFile.substring(0, oldFile.lastIndexOf("."))+".pdf";File file = new File(newFile); //新建一个空白pdf文档FileOutputStream os = new FileOutputStream(file);Document doc = new Document(oldFile); //Address是将要被转化的word文档ParagraphFormat pf=doc.getStyles().getDefaultParagraphFormat();pf.clearFormatting();doc.save(os, SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换return newFile;} catch (Exception e) {e.printStackTrace();}return null;}