LibreOffice to build and deploy automation scripts under Centos7

LibreOffice to build and deploy automation scripts under Centos7

Introduction to LibreOffice

LibreOffice is a powerful office suite - it's clear interface and powerful tool that allows you to unleash your creativity and increase your productivity.
Free free, all-powerful, cross-platform office suite
LibreOffice is a free open-source office software all-around free, runs on Microsoft Windows, GNU / Linux and other operating systems as well as macOS. It includes Writer, Calc, Impress, Draw, Math and Base and other components, can be used for text documents, spreadsheets, slide presentations, drawings, documents, mathematical formulas editor, database management, etc., respectively.
LibreOffice uses for businesses and individuals are free GPL 2.0 license. You can freely distribute the software without paying licensing fees (but you can still pay to get certified professional support). It's completely open source code, anyone can participate in the development and maintenance of the software.
It supports a variety of document formats
LibreOffice supports a variety of file formats. In addition to its native support for the Open Document Format (OpenDocument Format, ODF), it also supports a number of non-open format, such as Microsoft Microsoft® Word, Excel, PowerPoint and Publisher of formats.
Scalability
LibreOffice supports extensions. You can use LibreOffice Basic, Python, C / C ++, Java and other programming languages ​​for the development of LibreOffice extensions to enrich its functionality. LibreOffice extensions software library has more extensions available.
In addition, it also supports template, you can use LibreOffice template library in an existing template, or create your own templates.
Based on a powerful gene
LibreOffice, formerly known as OpenOffice.org , while OpenOffice.org was originally based on StarOffice. It is after many years of development and accumulation, and has been used by many users worldwide. Today, LibreOffice is the most active of the OpenOffice.org code base successor, every six months to release a major new version.
Official website: https://zh-cn.libreoffice.org/
LibreOffice is compatible with Microsoft Office series and other open-source office software depth, and supports document formats fairly comprehensive
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, a spreadsheet: .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. Presentation: .odp, .otp, .sti, .sxd, .fodp, .xml, .pptx, .pptm, .ppsx, .potm, .potx, .ppt, .pps, .pot, .sdd, .vor, * .sdp.
4, the drawing: .odg, .otg, .sxd, .std, .sgv, .sda, .vor, .sdd, .cdr, .svg, .vsd, .vst
5, pages: .html, .htm, * .stw
6, the master document:. * Sxg
7. formula: .odf, .sxm, .smf, .mml
8, database document:. * Odb
Overall, LibreOffice interface of Microsoft Office is not so gorgeous, but very simple and practical. Its six components corresponding to the Office no less, but also less demanding on system configuration, small footprint.

Building process

A mounting Libreoffice;

Download 3 rpm file

[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 file decompression;

[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

Into the RPMS directory

After each of the above three-extracting file which will have a RPMS folder, respectively, into each folder

[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遇到上面的依赖关系的时候可以从网络下载相应的包来解决依赖关系。】

So far libreoffice successfully installed, but the command can not, so we need to modify environment variables;

[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
#安装完成之后命令就可以使用了

Second, the document font solve the garbage problem after converting pdf;

To create a Chinese font folder

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

Fonts in the host computer in there, so go to C: \ Windows \ Fonts folder to copy fonts

Here Insert Picture Description

The fonts in linux, the position is the up / down chinese;

Here Insert Picture Description

Then all the fonts to the font directory and read permission;

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

Change font identification configuration file;

[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

Then you can use the command to convert

If you want to deploy a script to automate the conversion of how to do it? Because a dedicated server with the NFS mount to make the conversion, the script has been open state, where we wrote while an endless loop;

  • Environment: Centos7.6

  • The mount directory / opt / docx

  • Developers upload .docx file to opt / directory under its shared via NFS hang on to / docx

  • Will be converted into pdf files with complete conversion of docx file to a folder name / opt / files in a folder as today's date

Script as follows

[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                                                  ##执行脚本

Guess you like

Origin blog.csdn.net/weixin_44691065/article/details/91888726