SpringBoot中整合JodConverter實現(xiàn)文件在線預(yù)覽功能
Spring Boot中整合JodConverter實現(xiàn)文件在線預(yù)覽
1.安裝LibreOffice 24.2
LibreOffice 是一款功能強大的辦公軟件,默認使用開放文檔格式 (OpenDocument Format , ODF), 并支持 *.docx, *.xlsx, *.pptx 等其他格式。
它包含了 Writer, Calc, Impress, Draw, Base 以及 Math 等組件,可用于處理文本文檔、電子表格、演示文稿、繪圖以及公式編輯。
它可以運行于 Windows, GNU/Linux 以及 macOS 等操作系統(tǒng)上,并具有一致的用戶體驗。
2.Maven依賴
<!--文件預(yù)覽--> <!--轉(zhuǎn)換工具--> <dependency> <groupId>org.jodconverter</groupId> <artifactId>jodconverter-spring-boot-starter</artifactId> <version>4.4.2</version> </dependency> <dependency> <groupId>org.jodconverter</groupId> <artifactId>jodconverter-local</artifactId> <version>4.4.2</version> </dependency> <dependency> <groupId>org.jodconverter</groupId> <artifactId>jodconverter-core</artifactId> <version>4.4.2</version> </dependency>
3.配置文件
jodconverter: local: # 是否開啟緩存 enabled: true # libreOffice根目錄 officeHome: C:\Program Files\LibreOffice # 任務(wù)執(zhí)行的超時時間 taskExecutionTimeout: 86400000 # 任務(wù)隊列的超時時間 taskQueueTimeout: 86400000 # 端口(線程) portNumbers: [2001,2002,2003] # 一個進程的超時時間 processTimeout: 86400000
4.編寫業(yè)務(wù)Controller
@Autowired private DocumentConverter documentConverter; @GetMapping(value = "/onlinePreview") public void onlinePreview() { File source = new File("D:\\aaa.xls"); File target = new File("D:\\測試.html"); try { // source:源文件,target:轉(zhuǎn)換后的文件 // word-->pdf // ppt-->pdf // excel-->html documentConverter.convert(source).to(target).as(DefaultDocumentFormatRegistry.HTML).execute(); } catch (OfficeException e) { e.printStackTrace(); } }
以上就是SpringBoot中整合JodConverter實現(xiàn)文件在線預(yù)覽功能的詳細內(nèi)容,更多關(guān)于SpringBoot JodConverter文件在線預(yù)覽的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Google Kaptcha 框架實現(xiàn)登錄驗證碼功能(SSM 和 SpringBoot)
這篇文章主要介紹了Google Kaptcha 實現(xiàn)登錄驗證碼(SSM 和 SpringBoot)功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-12-12springboot如何從數(shù)據(jù)庫獲取數(shù)據(jù),用echarts顯示(數(shù)據(jù)可視化)
這篇文章主要介紹了springboot如何從數(shù)據(jù)庫獲取數(shù)據(jù),用echarts顯示(數(shù)據(jù)可視化),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12SpringBoot Devtools實現(xiàn)項目熱部署的方法示例
這篇文章主要介紹了SpringBoot Devtools實現(xiàn)項目熱部署的方法示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-01-01SpringBoot參數(shù)驗證的幾種方式小結(jié)
在日常的接口開發(fā)中,為了防止非法參數(shù)對業(yè)務(wù)造成影響,經(jīng)常需要對接口的參數(shù)進行校驗,例如登錄的時候需要校驗用戶名和密碼是否為空,所以本文介紹了SpringBoot參數(shù)驗證的幾種方式,需要的朋友可以參考下2024-07-07