Jodconverter開發(fā)環(huán)境搭建

  1. 官方網(wǎng)站下載 jodconverter 開發(fā)包。
下載.png

2.解壓下載后的開發(fā)包,將lib下的jar包全部拷貝到項(xiàng)目中去。


引入jar.png

3.附文檔轉(zhuǎn)換源碼

    /**
     * 可以將一種類型的文檔轉(zhuǎn)化為另一種類型,例如:.doc 轉(zhuǎn)為 .pdf
     * 
     * @param sourcePath
     *            源文件路徑
     * @param destPath
     *            目標(biāo)文件路徑
     * @return
     */
    public int turn(String sourcePath, String destPath) {
        try {
            File inputFile = new File(sourcePath);
            if (!inputFile.exists()) {
                return -1;// 找不到源文件, 則返回-1
            }
            File outputFile = new File(destPath);
            // 連接到openOffice服務(wù)
            OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
            connection.connect();
            // 將源文件轉(zhuǎn)換為目標(biāo)文件
            DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
            converter.convert(inputFile, outputFile);
            // 關(guān)閉連接服務(wù)
            connection.disconnect();
            return 0;
        } catch (ConnectException e) {
            e.printStackTrace();
        }
        return 1;
    }

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容