最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java 使用openoffice進(jìn)行word轉(zhuǎn)換為pdf的方法步驟

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

一、下載openoffice第三方工具

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

二、開(kāi)啟openoffice服務(wù)

找到openoffice安裝目錄下OpenOffice 4\program>soffice運(yùn)行cmd,運(yùn)行命令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運(yùn)行cmd
        // 開(kāi)啟open office命令:soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

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

    }

    /*
        具體的轉(zhuǎn)換方法
     */
    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
            }
            // 如果目標(biāo)路徑不存在, 則新建該路徑
            File outputFile = new File(destFile);
            if (!outputFile.getParentFile().exists()) {
                outputFile.getParentFile().mkdirs();
            }

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

            // 進(jìn)行轉(zhuǎn)換
            DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
            converter.convert(inputFile, outputFile);

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

waven倉(cāng)庫(kù)的配置依賴信息

  <!-- 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>

需要注意的問(wèn)題:
由于依賴版本原因轉(zhuǎn)換不了docx文件。

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

相關(guān)文章

  • Java之Spring Bean 作用域和生命周期

    Java之Spring Bean 作用域和生命周期

    這篇文章主要介紹了Java Bean的作用域和生命周期,Bean 的作用域是指 Bean 在 Spring 整個(gè)框架中的某種行為模式,所謂的?命周期指的是?個(gè)對(duì)象從誕?到銷毀的整個(gè)?命過(guò)程,我們把這個(gè)過(guò)程就叫做?個(gè)對(duì)象的?命周期,感興趣的同學(xué)可以參考閱讀
    2023-04-04
  • SpringBoot+MinIO實(shí)現(xiàn)對(duì)象存儲(chǔ)方式

    SpringBoot+MinIO實(shí)現(xiàn)對(duì)象存儲(chǔ)方式

    這篇文章主要介紹了SpringBoot+MinIO實(shí)現(xiàn)對(duì)象存儲(chǔ)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • java ant 配置及構(gòu)建項(xiàng)目圖文教程

    java ant 配置及構(gòu)建項(xiàng)目圖文教程

    以下是對(duì)java ant配置及構(gòu)建項(xiàng)目進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下
    2013-08-08
  • SpringBoot 內(nèi)嵌 camunda的配置方法

    SpringBoot 內(nèi)嵌 camunda的配置方法

    Camunda是一個(gè)基于Java的框架,支持用于工作流和流程自動(dòng)化的BPMN、用于案例管理的CMMN和用于業(yè)務(wù)決策管理的DMN,這篇文章主要介紹了SpringBoot 內(nèi)嵌 camunda,需要的朋友可以參考下
    2024-06-06
  • Java詳細(xì)分析講解自動(dòng)裝箱自動(dòng)拆箱與Integer緩存的使用

    Java詳細(xì)分析講解自動(dòng)裝箱自動(dòng)拆箱與Integer緩存的使用

    裝箱就是把基本類型轉(zhuǎn)換成包裝類,拆箱就是把包裝類轉(zhuǎn)換成基本類型,下面這篇文章主要給大家介紹Java中自動(dòng)裝箱、自動(dòng)拆箱與Integer緩存,需要的朋友可以參考下
    2022-04-04
  • Java Pattern和Matcher字符匹配方式

    Java Pattern和Matcher字符匹配方式

    這篇文章主要介紹了Java Pattern和Matcher字符匹配方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • java?cpu飆升問(wèn)題的詳細(xì)分析和處理方法

    java?cpu飆升問(wèn)題的詳細(xì)分析和處理方法

    Java中CPU占用過(guò)高是一個(gè)常見(jiàn)的問(wèn)題,可能是由于線程過(guò)多、死循環(huán)、長(zhǎng)時(shí)間的阻塞、死鎖、GC頻繁等原因?qū)е碌?這篇文章主要介紹了java?cpu飆升問(wèn)題的詳細(xì)分析和處理方法,需要的朋友可以參考下
    2025-03-03
  • Spring Boot 實(shí)例化bean如何選擇代理方式

    Spring Boot 實(shí)例化bean如何選擇代理方式

    這篇文章主要為大家介紹了Spring Boot實(shí)例化bean如何選擇代理方式詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • Java實(shí)現(xiàn)滑動(dòng)窗口算法的示例代碼

    Java實(shí)現(xiàn)滑動(dòng)窗口算法的示例代碼

    滑動(dòng)窗口算法是一種高效解決子數(shù)組、子字符串問(wèn)題的算法,廣泛應(yīng)用于數(shù)據(jù)流處理、網(wǎng)絡(luò)限流和字符串操作等場(chǎng)景,本文將詳細(xì)解析滑動(dòng)窗口算法的核心思想、常見(jiàn)問(wèn)題及其實(shí)現(xiàn)方式,需要的朋友可以參考下
    2025-03-03
  • Java接口請(qǐng)求重試機(jī)制的幾種常見(jiàn)方法

    Java接口請(qǐng)求重試機(jī)制的幾種常見(jiàn)方法

    Java接口請(qǐng)求重試機(jī)制是保證系統(tǒng)穩(wěn)定性和容錯(cuò)能力的重要手段之一,當(dāng)接口請(qǐng)求發(fā)生失敗或暫時(shí)性錯(cuò)誤時(shí),通過(guò)重試機(jī)制可以提高請(qǐng)求的成功率,本文將詳細(xì)介紹Java接口請(qǐng)求重試機(jī)制的幾種常見(jiàn)方法,需要的朋友可以參考下
    2023-11-11

最新評(píng)論

呼伦贝尔市| 沁源县| 海安县| 和静县| 聂拉木县| 巫溪县| 布尔津县| 营口市| 永清县| 木兰县| 雷山县| 呼玛县| 延边| 凌源市| 清水河县| 嘉义市| 闸北区| 福贡县| 松溪县| 济阳县| 靖远县| 临夏市| 普定县| 陕西省| 南部县| 个旧市| 苏尼特左旗| 安宁市| 汉川市| 改则县| 牙克石市| 云阳县| 河北区| 故城县| 新营市| 金溪县| 英德市| 中超| 株洲市| 富源县| 阳泉市|