這期內容當中小編將會給大家帶來有關使用openOffice如何實現將office文件轉換成pdf文件,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
下載安裝openoffice,

輸入cmd回車

在命令窗口輸入
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" –nofirststartwizard
此時服務就開啟了將以下代碼放到工具類里面,直接調用即可
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("程序出現問題,文件不存在");
}
// 輸出文件目錄
File outputFile = new File(pdfPath);
if (!outputFile.exists()) {
outputFile.createNewFile();
}
// 調用openoffice服務線程
String command = openOfficeCommand;
Process process = Runtime.getRuntime().exec(command);
// 連接openoffice服務
OpenOfficeConnection connection = new SocketOpenOfficeConnection(openOfficeUrl, openOfficePort);
connection.connect();
// 轉換word到pdf
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// 關閉連接
connection.disconnect();
// 關閉進程
process.destroy();
return outputFile;
}
...上述就是小編為大家分享的使用openOffice如何實現將office文件轉換成pdf文件了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。