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