java openoffic linux_CentOS 下安装 OpenOffice4.0

本文档详细介绍了如何在CentOS系统上安装OpenOffice4.0,包括下载、解压、安装依赖、启动服务以及解决安装过程中遇到的库文件缺失问题。此外,还展示了使用Java API进行OpenOffice文档转PDF的操作示例。
摘要由CSDN通过智能技术生成

或直接命令下载:wget http://heanet.dl.sourceforge.net/project/openofficeorg.mirror/4.0.0/binaries/zh-CN/Apache_OpenOffice_4.0.0_Linux_x86-64_install-rpm_zh-CN.tar.gz

放到服务器的目录下(我放到了opt下)

2、将下载的openoffice解压(我直接解压到opt目录):tar -zxvf Apache_OpenOffice_4.0.0_Linux_x86-64_install-rpm_zh-CN.tar.gz

3、解压后生成文件夹zh-CN 进到RPMS目录下,直接yum localinstall *.rpm

4、再装RPMS/desktop-integration目录下的openoffice4.0-redhat-menus-4.0-9702.noarch.rpm:yum localinstall openoffice4.0-redhat-menus-4.0-9702.noarch.rpm(注意:OpenOffice的运行需要JRE环境,因此要先把JDK安装好)

5、安装完成直接启动Openoffice服务:

临时启动   /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

一直后台启动 nohup  /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &

6、查看服务是否启动(端口8100是否被soffice占用):netstat -lnp |grep 8100

显示结果:tcp        0      0 127.0.0.1:8100              0.0.0.0:*                   LISTEN      19501/soffice.bin

7.-安装遇到的问题和解决------原则是缺什么补什么包

1、/opt/openoffice4/program/soffice.bin: error while loading shared libraries: libXext.so.6: cannot open shared object file: No such file or directory

https://pkgs.org/download/libXext.so.6()(64bit)

安装  libXext rpm 或者yum install libXext.i686

2、 /opt/openoffice4/program/soffice.bin: error while loading shared libraries: libfreetype.so.6: cannot open shared object file: No such file or directory

找不到libfreetype.so.6文件,同上输入:yum install libfreetype.i686,安装完之后去那两个目录找libXext.so.6复制到/opt/openoffice4/program/目录里面,赋予权限。

3、报问题:no suitable windowing system found, exiting.

输入安装:yum groupinstall "X Window System" ,一路安装完之后重启系统,在启动openoffice服务看看。

8.java调用openOffice服务

2.java调用

package com.kerryzb.util;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.net.ConnectException;

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

/**

* 将Office文档转换为PDF. 运行该函数需要用到OpenOffice, OpenOffice下载地址为

* http://www.openoffice.org/

*

*

 
 

* 方法示例:

* String sourcePath = "F:\\office\\source.doc";

* String destFile = "F:\\pdf\\dest.pdf";

* Converter.office2PDF(sourcePath, destFile);

*

*

* @param sourceFile

* 源文件, 绝对路径. 可以是Office2003-2007全部格式的文档, Office2010的没测试. 包括.doc,

* .docx, .xls, .xlsx, .ppt, .pptx等. 示例: F:\\office\\source.doc

* @param destFile

* 目标文件. 绝对路径. 示例: F:\\pdf\\dest.pdf

* @return 操作成功与否的提示信息. 如果返回 -1, 表示找不到源文件, 或url.properties配置错误; 如果返回 0,

* 则表示操作成功; 返回1, 则表示转换失败

*/

public static int office2PDF(String sourceFile, String destFile) throws FileNotFoundException {

try {

File inputFile = new File(sourceFile);

if (!inputFile.exists()) {

return -1;// 找不到源文件, 则返回-1

}

// 如果目标路径不存在, 则新建该路径

File outputFile = new File(destFile);

if (!outputFile.getParentFile().exists()) {

outputFile.getParentFile().mkdirs();

}

// connect to an OpenOffice.org instance running on port 8100

OpenOfficeConnection connection = new SocketOpenOfficeConnection(

"127.0.0.1", 8100);

connection.connect();

// convert

DocumentConverter converter = new OpenOfficeDocumentConverter(

connection);

converter.convert(inputFile, outputFile);

// close the connection

connection.disconnect();

return 0;

} catch (ConnectException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return 1;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值