上一篇记录了安装libreoffice的方式将office文档转换成pdf,接下来将使用openoffice实现同样的功能。
首先到openoffice官网下载最新的rpm压缩包:
https://www.openoffice.org/download/index.html
目前我下载最的的是:Apache_OpenOffice_4.1.3_Linux_x86-64_install-rpm_zh-CN.tar.gz
解压并进入到相关目录安装rpm包:
[root@instance-32spzihn src]# tar -zxvf Apache_OpenOffice_4.1.3_Linux_x86-64_install-rpm_zh-CN.tar.gz
[root@instance-32spzihn src]# cd zh-CN/RPMS
[root@instance-32spzihn RPMS]# yum install *.rpm
[root@instance-32spzihn RPMS]# cd /opt/openoffice4/program
安装完成并进入到对应的program目录之后,启动openoffice:
[root@instance-32spzihn program]# ./soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
发现报错:
[root@instance-32spzihn program]# javaldx: Could not find a Java Runtime Environment!
不过openoffice服务已经启动,由于只需要用到转换接口命令,不影响功能的情况下,我就不深究了。
接下来就需要一份python的脚本程序,因为转换需要通过py程序去调用api处理,将下面程序保存到topdf.py文件:
#
# PyODConverter (Python OpenDocument Converter) v1.1 - 2009-11-14
#
# This script converts a document from one office format to another by
# connecting to an OpenOffice.org instance via Python-UNO bridge.
#
# Copyright (C) 2008-2009 Mirko Nasato <mirko@artofsolving.com>
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl-2.1.html
# - or any later version.
#
DEFAULT_OPENOFFICE_PORT = 8100
import uno
from os.path import abspath, isfile, splitext
from com.sun.star.beans import PropertyValue
from com.sun.star.task import ErrorCodeIOException
from com.sun.star.connection import NoConnectException
FAMILY_TEXT = "Text"
FAMILY_WEB = "Web"
FAMILY_SPREADSHEET = "Spreadsheet"
FAMILY_PRESENTATION = "Presentation"
FAMILY_DRAWING = "Drawing"
#-------