您好,登錄后才能下訂單哦!
這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)使用openOffice如何實(shí)現(xiàn)將office文件轉(zhuǎn)換成pdf文件,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
下載安裝openoffice,
輸入cmd回車
在命令窗口輸入
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" –nofirststartwizard
此時(shí)服務(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; } ...
上述就是小編為大家分享的使用openOffice如何實(shí)現(xiàn)將office文件轉(zhuǎn)換成pdf文件了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。