openoffice java awt_使用openoffice转pdf,详细

期由于项目的需求,需要word文档转pdf在线预览,由于一直没有接触这块,所以花了将近四天时间才弄明白。

写这篇文章的主要目的是加深自己的记忆,同时方便以后在用。

(最近有使用了这个功能,发现这篇文章有很多问题,已修改,抱歉)

所需要的工具openoffice

在openoffice安装成功之后,需要在安装目录下porgram文件下打开cmd命令行输入

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

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

这时会启动两个openoffice的进程,打开任务管理器就可以看见。

pom.xml

com.artofsolving

jodconverter-maven-plugin

2.2.1

com.artofsolving

jodconverter-maven-plugin

2.2.1

在这里需要详细讲解一下openoffice的安装,最好是默认安装路径

安装完之后就开始干正事了。、

首先我们要先写一个上传页面(名字随意,我写的是jsp页面)

pageEncoding="utf-8"%>

html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Insert title here

.fileinput-button {

position: relative;

display: inline-block;

overflow: hidden;

}

.fileinput-button input{

position:absolute;

right: 0px;

top: 0px;

opacity: 0;

-ms-filter: 'alpha(opacity=0)';

font-size: 200px;

}

上传文件

pageEncoding="utf-8"%>

Insert title here

.fileinput-button {

position: relative;

display: inline-block;

overflow: hidden;

}

.fileinput-button input{

position:absolute;

right: 0px;

top: 0px;

opacity: 0;

-ms-filter: 'alpha(opacity=0)';

font-size: 200px;

}

上传文件

up55.png

在这里面我是加了bootstar,bootstar可以自行在百度下载。

在其up55说我在网上下载的上传图标,为了页面好看点

再接下来是controller

//这个方法是跳转到jsp的方法

@RequestMapping("/othre")

public String otre(){ return "otre"; }

//这个方法是上传的方法

@RequestMapping(value = "/upload", method = RequestMethod.POST)

@ResponseBody

public String upload(@RequestParam("file") MultipartFile file) throws IOException {

if (!file.isEmpty()) {

try {

// 这里只是简单例子,文件直接输出到项目路径下。

// 实际项目中,文件需要输出到指定位置,需要在增加代码处理。

BufferedOutputStream out = new BufferedOutputStream(

new FileOutputStream("d:/pdf/"+file.getOriginalFilename()));

System.out.println(file.getOriginalFilename());

out.write(file.getBytes());

out.flush();

out.close();

} catch (FileNotFou

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值