welcome to xlongwei.com

欢迎大家一起学习、交流、分享


QQ:9167702333 邮箱:admin@xlongwei.com

linux环境安装openoffice


分类 Linux   关键字 分享   标签 linux   发布 hongwei  1469679677102
注意 转载须保留原文链接,译文链接,作者译者等信息。  
openoffice支持doc转pdf,配合jodconverter方便Java代码调用,这里记录一下openoffice的安装过程。

CentOS 5.10
yum groupinstall "Office/Productivity"
yum list openoffice*
yum -y install openoffice.org-langpack-zh_CN #中文包
yum -y install openoffice.org-headless.x86_64 #解决:Can't Open Display
安装路径:/usr/lib64/openoffice.org3/program

CentOS 6.5,由于yum没有找到office相关包,因此直接下载rpm安装包
wget http://jaist.dl.sourceforge.net/project/openofficeorg.mirror/4.1.2/binaries/zh-CN/Apache_OpenOffice_4.1.2_Linux_x86-64_install-rpm_zh-CN.tar.gz
rpm -ivh *.rpm
安装路径,
/opt/openoffice4/program,可以考虑加入path
中文乱码问题解决:缺少中文字体目录/usr/share/fonts/chinese,下载地址:http://t.xlongwei.com/softwares/chinese.tar.gz
openoffice-4.1.2版本支持stream方式远程调用

soffice启动脚本
soffice -headless -accept="socket,host=0.0.0.0,port=8100;urp;StarOffice.ServiceManager" -nofirststartwizard &

doc转pdf测试
wget http://ncu.dl.sourceforge.net/project/jodconverter/JODConverter/2.2.2/jodconverter-2.2.2.zip
java -jar jodconverter-cli-2.2.2.jar  test.doc test.pdf

java驱动代码,PdfUtil
/** 转换文件格式
* @param source 支持doc(x) xls(x) ppt(x) txt(rtf) (x)html
* @param target 支持pdf html
*/
public static boolean convert(File source, File target) {
OpenOfficeConnection connection = new SocketOpenOfficeConnection(GlobalConfig.getProperty("pdf.soffice.host", "127.0.0.1"), NumberUtil.parseInt(GlobalConfig.getProperty("pdf.soffice.port"), 8100));
try {
connection.connect();
DocumentConverter converter = NumberUtil.parseBoolean(GlobalConfig.getProperty("pdf.soffice.stream"), false) ?
new MyStreamOpenOfficeDocumentConverter(connection) : //远程host:port
new MyOpenOfficeDocumentConverter(connection); //本机8100
logger.info("convert file, source: "+source.getAbsolutePath()+", target: "+target.getAbsolutePath());
long s = System.currentTimeMillis();
converter.convert(source, target);
connection.disconnect();
logger.info("convert file office manager disconnect, converted in ms: "+(System.currentTimeMillis()-s));
return true;
} catch (ConnectException e) {
logger.warn("fail to convert file, source: "+source.getAbsolutePath()+", target: "+target.getAbsolutePath(), e);
}
return false;
}