Centos7下的LibreOffice的搭建及自动化脚本部署

Centos7下的LibreOffice的搭建及自动化脚本部署

LibreOffice 简介

LibreOffice 是一个强大的办公套件 – 它清晰的界面和强大的工具让您释放您的创造力并增长您的生产力。
自由免费、全能、跨平台的办公套件
LibreOffice 是一款开放源代码的自由免费全能办公软件,可运行于 Microsoft Windows, GNU/Linux 以及 macOS 等操作系统上。它包含了 Writer, Calc, Impress, Draw, Math 以及 Base 等组件,可分别用于文本文档、电子表格、幻灯片演示文稿、绘图文档、数学公式编辑、数据库管理等工作。
LibreOffice 采用对企业和个人用户均免费的 GPL 2.0 授权协议。您可以自由分发该软件,无需支付授权费用(但您仍然可以付费获得经认证的专业支持)。它的源代码完全公开,任何人都可以参与软件的开发和维护。
支持各种文档格式
LibreOffice 支持各种文档格式。除了它原生支持的开放文档格式 (OpenDocument Format, ODF) 外,它还支持许多的非开放格式,比如微软的 Microsoft® Word, Excel, PowerPoint 以及 Publisher 的格式等。
可扩展性
LibreOffice 支持扩展功能。您可以使用 LibreOffice Basic, Python, C/C++, Java 等多个编程语言为 LibreOffice 开发扩展程序,以丰富其功能。LibreOffice的扩展软件库中已经有多个扩展可用。
另外,它还支持模板功能,您可以使用 LibreOffice 模板库中已有的模板,或者创建自己的模板。
基于强大的基因
LibreOffice 的前身是 OpenOffice.org, 而 OpenOffice.org 最早是基于 StarOffice。它经过了许多年的开发和积累,并已被全球范围内的众多用户使用。今天,LibreOffice 是目前最活跃的 OpenOffice.org 代码库后继者,每 6 个月发布一个主要的新版本。
官网:https://zh-cn.libreoffice.org/
LibreOffice 能够与 Microsoft Office 系列以及其它开源办公软件深度兼容,且支持的文档格式相当全面
1、文本文档:.odm, .sgl, .odt,.ott, .sxw, .stw, .fodt, .xml, .docx,.docm, .dotx, .dotm, .doc, .dot, .wps, .pdb, .hwp, .html, .htm, .lwp, .psw, .rft, .sdw, .vor, .txt, .wpd ,*.oth.
2、电子表格:.ods, .ots, .sxc, .stc, .fods, .xml, .xlsx, .xlsm, .xltm, .xltx, .xlsb, .xls, .xlc, .xlm, .xlw, .xlk, .sdc, .vor, .dif,.wk1, .wks, .123, .pxl, .wb2, *.csv.
3、演示文稿:.odp, .otp, .sti, .sxd, .fodp, .xml, .pptx, .pptm, .ppsx, .potm, .potx, .ppt, .pps, .pot, .sdd, .vor, *.sdp.
4、绘图:.odg, .otg, .sxd, .std, .sgv,.sda, .vor, .sdd, .cdr, .svg, .vsd, .vst
5、网页:.html, .htm, *.stw
6、主控文档:*.sxg
7、公式:.odf, .sxm, .smf, .mml
8、数据库文档:*. odb
总的来说,LibreOffice的界面没有微软Office那么华丽,但非常简单实用。它的六大组件对应Office丝毫不差,而且对系统配置要求较低,占用资源很少。

搭建过程

一、安装Libreoffice;

下载3个rpm文件

[root@Libreoffice ~]# wget http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/6.2.4/rpm/x86_64/LibreOffice_6.2.4_Linux_x86-64_rpm.tar.gz
[root@Libreoffice ~]# wget http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/6.2.4/rpm/x86_64/LibreOffice_6.2.4_Linux_x86-64_rpm_langpack_zh-CN.tar.gz
[root@Libreoffice ~]# wget http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/6.2.4/rpm/x86_64/LibreOffice_6.2.4_Linux_x86-64_rpm_sdk.tar.gz
[root@Libreoffice ~]# ls
LibreOffice_6.2.4_Linux_x86-64_rpm_langpack_zh-CN.tar.gz  LibreOffice_6.2.4_Linux_x86-64_rpm_sdk.tar.gz  LibreOffice_6.2.4_Linux_x86-64_rpm.tar.gz
##当本版本资源不可用时 访问http://mirrors.ustc.edu.cn/tdf/libreoffice/stable寻找新版本;

解压rpm文件;

[root@Libreoffice ~]# mkdir /usr/libreoffice
[root@Libreoffice ~]# tar zxf LibreOffice_6.2.4_Linux_x86-64_rpm.tar.gz -C /usr/libreoffice/
[root@Libreoffice ~]# tar zxf LibreOffice_6.2.4_Linux_x86-64_rpm_sdk.tar.gz -C /usr/libreoffice/
[root@Libreoffice ~]# tar zxf LibreOffice_6.2.4_Linux_x86-64_rpm_langpack_zh-CN.tar.gz -C /usr/libreoffice/
[root@Libreoffice ~]# ls /usr/libreoffice/
LibreOffice_6.2.4.2_Linux_x86-64_rpm                 LibreOffice_6.2.4.2_Linux_x86-64_rpm_sdk
LibreOffice_6.2.4.2_Linux_x86-64_rpm_langpack_zh-CN

进入到的RPMS目录

上面三个文件解压之后 每个里面都会有一个RPMS的文件夹,分别进入每个文件夹

[root@Libreoffice ~]# cd /usr/libreoffice/
[root@Libreoffice libreoffice]# cd LibreOffice_6.2.4.2_Linux_x86-64_rpm/RPMS/
[root@Libreoffice RPMS]#yum localinstall *.rpm
[root@Libreoffice libreoffice]# cd ..
[root@Libreoffice libreoffice]# cd LibreOffice_6.2.4.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS/
[root@Libreoffice RPMS]#yum localinstall *.rpm
[root@Libreoffice libreoffice]# cd ..
[root@Libreoffice libreoffice]# cd LibreOffice_6.2.4.2_Linux_x86-64_rpm_sdk/                        ##汉化包
[root@Libreoffice RPMS]#yum localinstall *.rpm
[root@Libreoffice libreoffice]# cd
##用yum来进行rpm的安装,不要用rpm命令来进行安装
##【注意:因为有依赖关系 libgnomevfs-2.so.0()(64bit),它被软件包 libobasis5.0-gnome-integration-5.0.4.2-2.x86_64 需要所以不要使用rpm命令来进行安装,rpm -ivh  *.rpm 命令无法解决上面的依赖系。使用yum遇到上面的依赖关系的时候可以从网络下载相应的包来解决依赖关系。】

到此为止libreoffice成功安装了,但是命令还不可以用,所以我们需要修改一下环境变量;

[root@Libreoffice ~]# vim /etc/profile
##在最后添加两行;
export LibreOffice_PATH=/opt/libreoffice6.2/program
export PATH=$LibreOffice_PATH:$PATH
:wq 保存并退出
[root@Libreoffice ~]# source /etc/profile                                                 ##重读环境变量
#这时命令就可以用了,命令格式如下
[root@Libreoffice ~]# soffice --headless --convert-to 目标格式(如pdf) 被转换位置(如/tmp/test.doc) --outdir 转换之后文件生成位置
#例:
[root@Libreoffice ~]# soffice --headless --convert-to pdf /root/test1.docx --outdir /opt/abc/
#当报错java的时候,需要安装java环境;解决方法:
[root@Libreoffice ~]# yum -y install java
#安装完成之后命令就可以使用了

二、解决转换pdf之后文档字体乱码问题;

先创建一个中文字体文件夹

[root@Libreoffice ~]# yum groupinstall "fonts"                                             ##安装字体识别目录
[root@Libreoffice ~]# cd /usr/share/fonts/                                                                       ##存放字体路径
[root@Libreoffice ~] #mkdir chinese/                                                                             ##创建中文目录
[root@Libreoffice ~]# cd chinese/

字体在主机电脑中就有,所以去C:\Windows\Fonts文件夹中去复制字体

在这里插入图片描述

将字体放到linux中,位置就是/chinese下;

在这里插入图片描述

然后给字体目录及所有字体可读权限;

[root@Libreoffice ~]# chmod -R 755 /usr/share/fonts/chinese/

修改字体的识别的配置文件;

[root@Libreoffice ~]# vi /etc/fonts/fonts.conf
#找到 Font directory list  字体列表,将目录改成/chinese下 
<dir>/usr/share/fonts/chinese</dir>                                                                            ##更改后
:wq 保存并推出
[root@Libreoffice ~]# fc-cache
[root@Libreoffice ~]# fc-list

接下来就可以使用命令来进行转换

如果想部署一个自动化转换的脚本该怎么做呢?由于有专门的服务器配合NFS挂载做转换,脚本状态一直开启,在这里我们写的while死循环;

  • 环境:Centos7.6

  • 被挂载目录 /opt/docx

  • 开发人员将.docx文件上传到其目录下 通过NFS挂在共享到/opt/docx下

  • 将转换成pdf的文件与转换完成的docx文件移动到/opt/文件夹中 文件夹名字为当天日期

脚本如下

[root@ceshi2 ~]# vi libreoffice.sh 
#/bin/bash                                                                        ##解释器
#author ouliwei                                                                   ##作者
#date 2019.6.10                                                                   ##完成时间
while true                                                                        ##while死循环
do
for i in /opt/docx/*.docx ;do
if [[ -f $i ]];then                                                               ##if判断是否有docx文件
  if [[ -d /opt/$(date +%F) ]];then                                               ##if判断是否有时间目录
    soffice --headless --convert-to pdf $i --outdir /opt/$(date +%F)
    mv $i /opt/$(date +%F)
  else
    mkdir /opt/$(date +%F)                                                        ##如果没有先创建
    soffice --headless --convert-to pdf $i --outdir /opt/$(date +%F)
    mv $i /opt/$(date +%F)                                                        ##移动已经转换完成的文件
    fi
else
  sleep 60                                                                        ##如果没有docx文件 则休眠一分钟(一分钟后再次从第一步开始)
fi
done
done
[root@ceshi2 ~]# chmod +x libreoffice.sh                                           ##加执行权限
[root@ceshi2 ~]# ./libreoffice.sh                                                  ##执行脚本

猜你喜欢

转载自blog.csdn.net/weixin_44691065/article/details/91888726