av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

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

二、開啟openoffice服務(wù)

找到openoffice安裝目錄下OpenOffice 4program>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 4program>soffice運(yùn)行cmd// 開啟open office命令:soffice -headless -accept='socket,host=127.0.0.1,port=8100;urp;' -nofirststartwizard// 獲取開始時(shí)間Date startDate = new Date();// 目標(biāo)文件(這里寫需要被轉(zhuǎn)換的文件地址和文件名)String sourceFile = 'C:Users86199Desktopaaa.doc';// 生成的文件(這里寫轉(zhuǎn)換為pdf的文件地址和文件名)String destFile = 'C:Users86199Desktop測試.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í)返回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>

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

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

標(biāo)簽: word
相關(guān)文章:
主站蜘蛛池模板: 搞av.com | 九九热精品视频 | 久久69精品久久久久久久电影好 | 国产成人网 | 国产一区二区三区视频 | 美国a级毛片免费视频 | 亚洲香蕉 | 中文字幕国产精品 | 日韩一| 国产1区| 综合久久综合久久 | 欧美日韩国产一区二区三区 | 亚洲精品久久久一区二区三区 | 欧美一级电影免费观看 | 狠狠干影院 | 久久一热 | 国产婷婷精品 | 麻豆亚洲 | 久艹网站 | 东方伊人免费在线观看 | 日本不卡一区 | 亚洲久草 | 毛片免费在线 | 在线视频91 | 国精产品一区一区三区免费完 | 亚洲视频在线观看免费 | 久草在线高清 | av二区三区 | 青青久草 | 国产视频一区二区在线观看 | 欧美日韩专区 | 亚洲色欲色欲www | 伊人色综合久久久天天蜜桃 | 精品久久久久国产 | 国产精品污www在线观看 | 国产精品亚洲一区二区三区在线 | 99精品一区二区三区 | 国产一区二区精品 | 99热.com| 国产精品1区2区3区 男女啪啪高潮无遮挡免费动态 | 国产精品视频在线观看 |