在项目开发过程中遇到word、pdf转图片 方便预览的问题,经过多次选择 最后用openoffice
Apache_OpenOffice_4.1.4_Linux_x86-64_install-rpm_zh-CN.tar.gz
官网下载太慢 下面是百度云盘链接
链接:https://pan.baidu.com/s/1mOLh4NEnmTX7AEciRLVVpQ
提取码:t8ba
复制这段内容后打开百度网盘手机App,操作更方便哦
1、下载完成之后 上传到linux服务器进行安装
编译安装:
本人资源包放在 /opt/moudles 中, 解压后放在 /opt/softwares 中
解压 openoffice 包
[root@localhost moudles]# tar -zxvf Apache_OpenOffice_4.1.4_Linux_x86-64_install-rpm_zh-CN.tar.gz -C ../softwares/
解压之后会在 /opt/softwares 中生成 文件夹,进入中文件夹。
[root@localhost moudles]# cd /opt/softwares/zh-CN/RPMS
运行 yum localinstall *.rpm
[root@localhost RPMS]# yum localinstall *.rpm
成功之后会在当前目录生成 文件夹,运行 yum localinstall 。
[root@localhost desktop-integration]# yum localinstall openoffice4.1.4-redhat-menus-4.1.4-9788.noarch.rpm
安装成功会在 /opt 目录下生成 文件夹。
启动:
临时启动: 临时启动之后画面就不会动了, 不要认为是死机。只要不报错就是好现象。
[root@localhost desktop-integration]# /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
永久启动:
[root@localhost desktop-integration]# nohup /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
查看是否启动成功:
[root@localhost opt]# ps -ef|grep openoffice
查看端口:
[root@localhost opt]# netstat -lnp |grep 8100
说明启动成功, 大功告成!
2、java代码部分
如果文件类型为word 则先转为pdf再转图片,如果是pdf则直接转为图片。
public String uploadWord2Pdf(HttpServletRequest request) throws Exception {
StringBuilder sb = new StringBuilder();
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request;
Map<String,MultipartFile> fileMap = multipartRequest.getFileMap();
if (fileMap != null) {
for (Map.Entry<String, MultipartFile> entity:fileMap.entrySet()) {
MultipartFile f = entity.getValue();
String fileName = f.getOriginalFilename();
String b = fileName.substring(fileName.indexOf(".")+1, fileName.length());
if(b.equals("doc")||b.equals("docx")) {
ObjectId id = gridFsTemplate.store(f.getInputStream(), f.getOriginalFilename(),f.getContentType());
File file = new File(id.toString()+"."+b);
FileTransType.inputstreamtofile