java Springboot word转换PDF, 支持doc和docx超简单 , 支持水印


首先下载jar

这里是链接地址

链接: https://pan.baidu.com/s/1YaMIp4No9yzD7eSG4oMb_A 提取码: wg1h 

 

我们需要在idea导入jar包

不会的直接看这里:

https://blog.csdn.net/superinzaghi747/article/details/80539095

然后在resource下创建xml文件

然后直接上代码:

 /** * 获取配置文件信息 * * @return boolean */ public static boolean getLicense() { try { InputStream is = FileUtils.class.getClassLoader().getResourceAsStream("License.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下 License license = new License(); license.setLicense(is); return true; } catch (Exception e) { e.printStackTrace(); } return false; } /** * 转换文件流 * * @param Address 本地文件地址 */ public static void doc2pdf(String Address) { if (getLicense()) { try { long old = System.currentTimeMillis(); File file = new File("C:\\Users\\18701\\Downloads\\test.pdf"); if (!file.exists()) { file.createNewFile(); } 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(); } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("转化失败"); } } public static void main(String[] args) { doc2pdf("C:\\Users\\18701\\Downloads\\1589765732905.doc"); }

如果下载返回的话直接返回流文件就可以了

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM