欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java 使用openoffice進行word轉換為pdf的方法步驟

 更新時間:2021年04月30日 09:24:35   作者:也許深情  
這篇文章主要介紹了Java 使用openoffice進行word轉換為pdf的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

一、下載openoffice第三方工具

建議下載4.1.6版本
http://www.openoffice.org/download/index.html

二、開啟openoffice服務

找到openoffice安裝目錄下OpenOffice 4\program>soffice運行cmd,運行命令soffice -headless -accept=“socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard

三、Java代碼

package com.ry.controller;

import java.io.File;
import java.util.Date;

import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;

public class PDTT {

    public static void main(String[] args) {
        // 找到openoffice安裝目錄下OpenOffice 4\program>soffice運行cmd
        // 開啟open office命令:soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

        // 獲取開始時間
        Date startDate = new Date();
        // 目標文件(這里寫需要被轉換的文件地址和文件名)
        String sourceFile = "C:\\Users\\86199\\Desktop\\aaa.doc";
        // 生成的文件(這里寫轉換為pdf的文件地址和文件名)
        String destFile = "C:\\Users\\86199\\Desktop\\測試.pdf";
        try {
            // 運行轉換方法
            System.out.println(office2PDF(sourceFile, destFile));
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 獲取結束時間
        Date endDate = new Date();
        System.out.println("總耗時:" + (endDate.getTime() - startDate.getTime()));

    }

    /*
        具體的轉換方法
     */
    public static int office2PDF(String sourceFile, String destFile) throws Exception {
        try {
            File inputFile = new File(sourceFile);
            // 判斷文件是否存在
            if (!inputFile.exists()) {
                System.out.println("源文件不存在");
                return -1;// 找不到源文件, 則返回-1
            }
            // 如果目標路徑不存在, 則新建該路徑
            File outputFile = new File(destFile);
            if (!outputFile.getParentFile().exists()) {
                outputFile.getParentFile().mkdirs();
            }

            // 連接到在端口8100上運行的OpenOffice.org實例
            OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
            connection.connect();

            // 進行轉換
            DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
            converter.convert(inputFile, outputFile);

            // 關閉連接
            connection.disconnect();
            // 執(zhí)行成功
            System.out.println("轉化成功");
            return 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 失敗時返回1
        return 1;
    }
}

waven倉庫的配置依賴信息

  <!-- Apache Utils -->
     <dependency>
         <groupId>commons-beanutils</groupId>
         <artifactId>commons-beanutils</artifactId>
         <version>1.8.0</version>
     </dependency>
     <dependency>
         <groupId>commons-codec</groupId>
         <artifactId>commons-codec</artifactId>
         <version>1.5</version>
     </dependency>
     <dependency>
         <groupId>commons-collections</groupId>
         <artifactId>commons-collections</artifactId>
         <version>3.2.1</version>
     </dependency>
     <dependency>
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-lang3</artifactId>
         <version>3.4</version>
     </dependency>
     <dependency>
         <groupId>commons-io</groupId>
         <artifactId>commons-io</artifactId>
         <version>2.4</version>
     </dependency>
     <!-- openoffice-->
     <dependency>
         <groupId>com.artofsolving</groupId>
         <artifactId>jodconverter</artifactId>
         <version>2.2.1</version>
     </dependency>

     <dependency>
         <groupId>org.openoffice</groupId>
         <artifactId>ridl</artifactId>
         <version>4.1.2</version>
     </dependency>

     <dependency>
         <groupId>org.openoffice</groupId>
         <artifactId>jurt</artifactId>
         <version>3.2.1</version>
     </dependency>

     <dependency>
         <groupId>org.openoffice</groupId>
         <artifactId>juh</artifactId>
         <version>3.1.0</version>
     </dependency>

     <dependency>
         <groupId>org.openoffice</groupId>
         <artifactId>unoil</artifactId>
         <version>3.0.0</version>
     </dependency>

     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
     </dependency>

     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
     </dependency>
     <dependency>
         <groupId>io.swagger</groupId>
         <artifactId>swagger-annotations</artifactId>
         <version>1.5.20</version>
     </dependency>
     <dependency>
         <groupId>org.mockito</groupId>
         <artifactId>mockito-core</artifactId>
     </dependency>
     <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>RELEASE</version>
         <scope>compile</scope>
     </dependency>
     <!-- https://mvnrepository.com/artifact/org.artofsolving.jodconverter/jodconverter-core -->
     <dependency>
         <groupId>org.artofsolving.jodconverter</groupId>
         <artifactId>jodconverter-core</artifactId>
         <version>3.0-beta-4</version>
     </dependency>

 </dependencies>

 <build>
     <plugins>
         <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
     </plugins>
 </build>

需要注意的問題:
由于依賴版本原因轉換不了docx文件。

到此這篇關于Java 使用openoffice進行word轉換為pdf的方法步驟的文章就介紹到這了,更多相關Java openoffice word轉換為pdf內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家! 

相關文章

  • Java中MapStruct入門使用及對比

    Java中MapStruct入門使用及對比

    MapStruct是一個Java注解處理器框架,用于簡化Java Bean之間的映射,本文主要介紹了Java中MapStruct入門使用及對比,感興趣的可以了解一下
    2023-12-12
  • SpringBoot整合定時任務的方法

    SpringBoot整合定時任務的方法

    通過 ThreadPoolExecutor 可以實現(xiàn)各式各樣的自定義線程池,而 ScheduledThreadPoolExecutor 類則在自定義線程池的基礎上增加了周期性執(zhí)行任務的功能,這篇文章主要介紹了SpringBoot整合定時任務,需要的朋友可以參考下
    2024-05-05
  • java8學習教程之lambda表達式的使用方法

    java8學習教程之lambda表達式的使用方法

    Java8最值得學習的特性就是Lambda表達式,下面這篇文章主要給大家介紹了關于java8學習教程之lambda表達式使用的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。
    2017-09-09
  • 擴展tk.mybatis的流式查詢功能實現(xiàn)

    擴展tk.mybatis的流式查詢功能實現(xiàn)

    mybatis查詢默認是一次獲取全部,如果數(shù)據(jù)過于龐大,就會導致OOM問題,本文就介紹了tk.mybatis 流式查詢,具有一定的參考價值,感興趣的可以了解一下
    2021-12-12
  • MyBatis動態(tài)Sql之if標簽的用法詳解

    MyBatis動態(tài)Sql之if標簽的用法詳解

    這篇文章主要介紹了MyBatis動態(tài)Sql之if標簽的用法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2019-07-07
  • Spring Data Jpa Mysql使用utf8mb4編碼的示例代碼

    Spring Data Jpa Mysql使用utf8mb4編碼的示例代碼

    這篇文章主要介紹了Spring Data Jpa Mysql使用utf8mb4編碼的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • 解決安裝mysqlclient的時候出現(xiàn)Microsoft Visual C++ 14.0 is required報錯

    解決安裝mysqlclient的時候出現(xiàn)Microsoft Visual C++ 14.0 is required報錯

    這篇文章主要介紹了解決安裝mysqlclient的時候出現(xiàn)Microsoft Visual C++ 14.0 is required報錯問題,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-11-11
  • Springboot MongoDB實現(xiàn)自增序列的項目實踐

    Springboot MongoDB實現(xiàn)自增序列的項目實踐

    在某些特定的業(yè)務場景下,會需要使用自增的序列來維護數(shù)據(jù),本文主要介紹了Springboot MongoDB實現(xiàn)自增序列的項目實踐,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-07-07
  • java開發(fā)web前端cookie session及token會話機制詳解

    java開發(fā)web前端cookie session及token會話機制詳解

    如果把人體比作一個web系統(tǒng)的話,cookie、session和token就好像人體的經(jīng)絡和血管一樣,而web系統(tǒng)中的數(shù)據(jù),就好像人體的血液一樣。血液依靠著血管在人體內(nèi)流動,就如數(shù)據(jù)根據(jù)cookie和session機制在web系統(tǒng)中流動一樣
    2021-10-10
  • Java中==與equals的區(qū)別小結

    Java中==與equals的區(qū)別小結

    這篇文章主要介紹了Java中==與equals的區(qū)別小結,本文總結結論:== 與 equals()比較的內(nèi)容是不同的,equals()方式是String類中的方法,它用于比較兩個對象引用所指的內(nèi)容是否相等,而 == 比較的是兩個對象引用的地址是否相等,需要的朋友可以參考下
    2015-06-06

最新評論