亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

通過openOffice將office文件轉(zhuǎn)成pdf

 更新時間:2020年11月17日 10:36:01   作者:龍谷情Sinoam  
這篇文章主要介紹了通過openOffice將office文件轉(zhuǎn)成pdf,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

下載安裝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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論