赞
踩
(参考如下文章):Java开发中Word转PDF文件5种方案横向评测_java word转pdf-CSDN博客
直接说这篇文章结果:
下载地址一(百度云): jdk,openoffice,windows字体,linux字体,jodconverter:2.2.2
链接: https://pan.baidu.com/s/1fPWTXiANsTuvBbJWogygfw 提取码: 9kfc --来自肥酱百度网盘超级会员v1的分享
下载地址二(官网): Apache OpenOffice - Official Download
下载地址二:Apache OpenOffice - Downloads
参考文章:https://blog.csdn.net/ruankun521/article/details/104639193
- 1.直接百度云下载包,或者官网下载,(官网的复制链接以后迅雷下载比较快)
- 2.配置环境变量,确定自己使用的是zsh还是bash,终端输入:
- echo $SHELL
- 3.我是使用的是zsh配置以下,编辑用户环境变量
- vim ~/.zshrc
- export PATH=$PATH:/Applications/OpenOffice.app/Contents/MacOS
- source ~/.zshrc
- 4.配置号以后终端直接启动socket,命令如下
- soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofiertstartwizard
- 1.安装方法相同,但是注意的是安装的位置不管选哪里的最终会在c盘有安装包
- 2.执行的时候soffice 换成soffice.exe就可以
- 3.遇到问题运行桌面应用程序以后,在运行soffice没有反应,需要在任务管理器杀死soffice的进程树
- 1.建立jdk存放目录
- mkdir /usr/local/java
- 2.解压压缩包并mv移动到目录
- tar -zxvf jdk1.8
- 3.配置vim /etc/profile
- # java environment
- export JAVA_HOME=/usr/local/java/jdk1.8
- export PATH=$PATH:${JAVA_HOME}/bin
- 4.更新配置
- source /etc/profile
- 1.解压压缩文件到当前目录
- tar -zxvf Apache_OpenOffice_4.1.4_Linux_x86-64_install-rpm_zh-CN.tar.gz
- 2.进入解压后文件
- cd zh-CN/RPMS/
- 3.安装文件下所有文件
- rpm -ivh *.rpm
- 4.安装完后进入desktop-integration安装另外一部分安装包,里面有几个安装包,如果是centos7的红帽的选下面的
- cd desktop-integration/
- rpm -ivh openoffice4.1.4-redhat-menus-4.1.4-9788.noarch.rpm
-
- 5.安装完成以后就启动试下
- soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
-
- ##如果报错就按照下面FAQ解决问题
- ##如果没有报错就查看有没有进程,如果有进程就成功了. 没有进程没有报错可能要删除以后重装(我就出现了这个情况)
-
- 6.启动方法
-
- 7.可以建立软连接,如果没有soffice软连接到/usr/bin那些就需要去目录启动
- soffice位置在/opt/openoffice4/program
-
- 8.本地启动直接127.0.0.1
- soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
-
- 9.远程启动需要把host定义本机ip地址
- soffice -headless -accept="socket,host=192.168.124.201,port=8100;urp;" -nofirststartwizard &
-
-
- 10.关闭服务,找到端口以后kill
- 查看端口
- ps -ef | grep 8100
- 查看进程
- ps -ef | grep soffice
- 查看所有端口
- netstat -lntp

在centos7下报错: /opt/openoffice4/program/soffice.bin: error while loading shared libraries: libXext.so.6: cannot open shared object file: No such file or directory 解决办法: yum install -y libXext.x86_64
centos中运行提示没有窗口,openOffice是应用程序可能需要这个支持,安装一个 问题: no suitable windowing system found, exiting. 解决方案:终端输入 yum -y groupinstall "X Window System"
macOs使用正常 centos运行报错 问题: com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: conversion failed: could not load input document 解决方案: DocumentConverter converter = new StreamOpenOfficeDocumentConverter(connection); 不要用OpenOfficeDocumentConverter
字体问题:这个问题在远程调用centos的服务时遇到了word中的中文不会转换,只有数字英文图片等会转换 (参考<<铭毅天下>>资料:http://blog.csdn.net/laoyang360/article/details/73555598) 解决方案: 1.在centos上查看字体配置文件 cat /etc/fonts/fonts.conf 2.看到位置在<dir>/usr/share/fonts</dir> 3.将下载的linux字体和windows字体都放在这个文件夹下 4.刷新字体缓存 fc-cache 5.kill openoffice进程 6.重启openoffice进程
问题五: centos执行后直接闪退
参考文章:https://blog.csdn.net/laoyang360/article/details/77342583
1.干掉安装包和文件
rpm -e `rpm -qa |grep openoffice` `rpm -qa |grep ooobasis`
rm -rf /opt/openoffice4
2.查看安装包是否还存在
rpm -q openoffice*
rpm -q ooobasis*
3.查看进程是否运行kill掉
4.查看多余文件
find / -name *openoffice*
5.按照流程继续安装
问题六: 代码提示导入失败,docx无法读取
如果使用的是jodconverter:2.2.1版本的jar包是无法读取docx文件并转换的,可以下载百度云提供的2.2.2版本
jodconverter仓库没有2.2.2 需要加入scope只读取本地的
问题七:wps打开pdf在100%缩放以下字体模糊
转换以后得文件苹果缩比例情况下使用wps打开会文字糊,office打开正常,怀疑是矢量的问题
- 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;
- import com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;
- import org.junit.jupiter.api.Test;
-
- import java.io.File;
- import java.net.ConnectException;
-
-
- public class MyOpenOffice {
- @Test
- public void test(){
-
- try {
- wordToPdf("/Users/chendada/Desktop/ideas.docx","/Users/chendada/Desktop/ideas3.pdf");
- } catch (ConnectException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static void wordToPdf(String docFile,String pdfFile) throws ConnectException {
- // 源文件目录
- File inputFile = new File(docFile);
- System.out.println( inputFile.getName());
- // 输出文件目录
- File outputFile = new File(pdfFile);
- if (!outputFile.getParentFile().exists()) {
- outputFile.getParentFile().exists();
- }
- // 连接openoffice服务
- OpenOfficeConnection connection = new SocketOpenOfficeConnection(
- // "127.0.0.1", 8100);
- "192.168.124.201", 8100);
- connection.connect();
- // 转换word到pdf
- DocumentConverter converter = new StreamOpenOfficeDocumentConverter(
- connection);
- converter.convert(inputFile, outputFile);
- // 关闭连接
- connection.disconnect();
- }
- }

- <!-- pom 文件-->
- <dependency>
- <groupId>org.openoffice</groupId>
- <artifactId>juh</artifactId>
- <version>4.1.2</version>
- </dependency>
-
- <dependency>
- <groupId>org.openoffice</groupId>
- <artifactId>unoil</artifactId>
- <version>4.1.2</version>
- </dependency>
- <!-- jodconverter仓库没有2.2.2 需要加入scope只读取本地的 -->
- <dependency>
- <groupId>com.artofsolving</groupId>
- <artifactId>jodconverter</artifactId>
- <version>2.2.2</version>
- <scope>system</scope>
- </dependency>

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。