色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:91日期:2022-05-22 17:33:47
一、下載openoffice第三方工具

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

二、開啟openoffice服務

找到openoffice安裝目錄下OpenOffice 4program>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 4program>soffice運行cmd// 開啟open office命令:soffice -headless -accept='socket,host=127.0.0.1,port=8100;urp;' -nofirststartwizard// 獲取開始時間Date startDate = new Date();// 目標文件(這里寫需要被轉換的文件地址和文件名)String sourceFile = 'C:Users86199Desktopaaa.doc';// 生成的文件(這里寫轉換為pdf的文件地址和文件名)String destFile = 'C:Users86199Desktop測試.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(); // 執行成功 System.out.println('轉化成功'); return 0;} catch (Exception e) { e.printStackTrace();}// 失敗時返回1return 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內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: word
相關文章:
主站蜘蛛池模板: 久久亚洲精品成人 | 精品久久久久久中文字幕一区 | 永久网站色视频在线观看免费 | 久久福利资源站免费观看i 久久高清精品 | 中国的毛片 | 杨幂丝袜国产福利视频 | 99久久国产综合精品五月天 | 久久精品视频7 | 在线免费观看毛片网站 | 免费播放特黄特色毛片 | 国内精品久久久久影院网站 | 国产精品成人久久久久久久 | 精品一区二区三区免费视频 | 国产精品一区二区四区 | 欧美激情精品久久久久久久久久 | 北岛玲亚洲一区在线观看 | a国产视频| 成人午夜性a一级毛片美女 成人午夜亚洲影视在线观看 | 韩国美女一级片 | 国产综合在线视频 | 日本不卡一区二区三区在线观看 | 久久久免费观看视频 | 久久久综合网 | 国产短视频精品一区二区三区 | 草草影院ccyy免费看片 | 国内一级野外a一级毛片 | 深夜福利网址 | 亚洲国产精品成 | 孕妇一级片 | 成年人视频在线免费看 | 国产年成美女网站视频免费看 | 97在线国产视频 | 亚洲精品一二三四区 | 草草影院永久在线观看 | 神马国产 | 亚洲人成亚洲人成在线观看 | 免费毛片儿| 欧美一级一极性活片免费观看 | 欧美日本亚洲国产一区二区 | 国产午夜精品理论片影院 | 一级特黄aaa大片免费看 |