word 转成pdf

首先下载openoffice 地址: 百度搜索 windows openoffice 下载安装  我先在windows下实验的

用一下命令启动openoffice服务

cd  到openoffice的安装路径 这里我的路径是C:\Program Files (x86)\OpenOffice 4\program

cd C:\Program Files (x86)\OpenOffice 4\program

然后执行命令

soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard


由于我的项目是Maven项目所以加了一个pom文件

<dependency>
<groupId>com.artofsolving</groupId>
<artifactId>jodconverter-maven-plugin</artifactId>
<version>2.2.1</version>
</dependency>

如果不是基于Maven的项目 则需要下载相关的jar包

jar包官网  http://www.artofsolving.com/opensource/jodconverter

主要用的jar应该是

jodconverter-2.2.2.jar 
jurt-2.3.0.jar 
xstream-1.2.2.jar 
ridl-2.3.0.jar 
commons-io-1.3.1.jar 
juh-2.3.0.jar 
slf4j-api-1.4.3.jar 
unoil-2.3.0.jar 
slf4j-jdk14-1.4.3.jar 

import java.io.File;


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 WordToPdf {


public static void toPdf(String docfile, String toFile) throws Exception{ 
File inputFile = new File(docfile); 
File outputFile = new File(toFile); 
// connect to an OpenOffice.org instance running on port 8100 
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); 
connection.connect(); 
// convert 
DocumentConverter converter = new OpenOfficeDocumentConverter(connection); 
converter.convert(inputFile, outputFile); 
// close the connection 
connection.disconnect(); 


http://titanseason.iteye.com/blog/1471606

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值