通過openOffice將office文件轉(zhuǎn)成pdf
下載安裝openoffice,下載地址:http://www.openoffice.org/download/我安裝的目錄:
輸入cmd回車
在命令窗口輸入
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" –nofirststartwizard
此時服務(wù)就開啟了將以下代碼放到工具類里面,直接調(diào)用即可
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter; ... ... public File office2Pdf(String srcPath, String pdfPath) throws Exception { // 源文件目錄 File inputFile = new File(srcPath); if (!inputFile.exists()) { throw new Exception("程序出現(xiàn)問題,文件不存在"); } // 輸出文件目錄 File outputFile = new File(pdfPath); if (!outputFile.exists()) { outputFile.createNewFile(); } // 調(diào)用openoffice服務(wù)線程 String command = openOfficeCommand; Process process = Runtime.getRuntime().exec(command); // 連接openoffice服務(wù) OpenOfficeConnection connection = new SocketOpenOfficeConnection(openOfficeUrl, openOfficePort); connection.connect(); // 轉(zhuǎn)換word到pdf DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(inputFile, outputFile); // 關(guān)閉連接 connection.disconnect(); // 關(guān)閉進(jìn)程 process.destroy(); return outputFile; } ...
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java使用openOffice對于word的轉(zhuǎn)換及遇到的問題解決
- linux環(huán)境下安裝 openOffice 并啟動服務(wù) 的方法
- Java利用openoffice將doc、docx轉(zhuǎn)為pdf實(shí)例代碼
- java調(diào)用openoffice將office系列文檔轉(zhuǎn)換為PDF的示例方法
- Java實(shí)現(xiàn)在線預(yù)覽的示例代碼(openOffice實(shí)現(xiàn))
- PHP調(diào)用OpenOffice實(shí)現(xiàn)word轉(zhuǎn)PDF的方法
- 解決linux下openoffice word文件轉(zhuǎn)PDF中文亂碼的問題
- Java仿文庫的基本方法(openoffice+swftools+flexPaper)
- java實(shí)現(xiàn)附件預(yù)覽(openoffice+swftools+flexpaper)實(shí)例
相關(guān)文章
Java如何獲取Json中的數(shù)據(jù)實(shí)例代碼
這篇文章主要給大家介紹了關(guān)于Java如何獲取Json中數(shù)據(jù)的相關(guān)資料,我們在日常開發(fā)中少不了和JSON數(shù)據(jù)打交道,那么我們來看看JAVA中常用的JSON獲取方式,需要的朋友可以參考下2023-09-09Spring Boot + Vue 前后端分離開發(fā)之前端網(wǎng)絡(luò)請求封裝與配置
這篇文章主要介紹了Spring Boot + Vue 前后端分離開發(fā)之前端網(wǎng)絡(luò)請求封裝與配置方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值 ,需要的朋友可以參考下2019-05-05Java開發(fā)或調(diào)用WebService的幾種方式總結(jié)
java開發(fā)過程中,很多地方都會遇到數(shù)據(jù)傳遞,遠(yuǎn)程獲取數(shù)據(jù)問題,這篇文章主要介紹了Java開發(fā)或調(diào)用WebService的幾種方式的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-06-06Java遠(yuǎn)程執(zhí)行shell命令出現(xiàn)java: command not found問題及解決
這篇文章主要介紹了Java遠(yuǎn)程執(zhí)行shell命令出現(xiàn)java: command not found問題及解決方案,具有很好的參考價值,希望對大家有所幫助。2023-07-07IDEA上面搭建一個SpringBoot的web-mvc項(xiàng)目遇到的問題
這篇文章主要介紹了IDEA上面搭建一個SpringBoot的web-mvc項(xiàng)目遇到的問題小結(jié),需要的朋友可以參考下2017-04-04spring boot+mybatis 多數(shù)據(jù)源切換(實(shí)例講解)
下面小編就為大家?guī)硪黄猻pring boot+mybatis 多數(shù)據(jù)源切換(實(shí)例講解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09Java二分法查找_動力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了Java二分法查找的相關(guān)資料,需要的朋友可以參考下2017-04-04