下载并安装 LibreOffice 6.3.4

除了下载主安装包外,还需要下载中文包,我下载到的两个文件分别是:

  • LibreOffice_6.3.4_Linux_x86-64_rpm.tar.gz
  • LibreOffice_6.3.4_Linux_x86-64_rpm_langpack_zh-CN.tar.gz

分别解压:

1
2
tar -xzvf LibreOffice_6.3.4_Linux_x86-64_rpm.tar.gz
tar -xzvf LibreOffice_6.3.4_Linux_x86-64_rpm_langpack_zh-CN.tar.gz

分别进入这两个文件的 RPMS 目录,用命令 yum localinstall *.rpm 执行本地安装,我解压后的两个目录:

1
2
cd /root/soft/LibreOffice_6.3.4.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS
cd /root/soft/LibreOffice_6.3.4.2_Linux_x86-64_rpm/RPMS

执行 libreoffice6.3 --version 查看版本,提示:

1
/opt/libreoffice6.3/program/soffice.bin: error while loading shared libraries: libcairo.so.2: cannot open shared object file: No such file or directory

解决:安装相应的依赖

1
yum -y install cairo cups-libs libSM

安装中文字体

仅仅安装官方的中文字体包是不够的,很多时候我们要转换的中文 .doc/.docx,.ppt/.pptx 文件,用到的字体都是 windows 系统下面的,所以,需要把 windows 系统下面的中文字体全部都安装到 CentOS7 上。

在终端执行 sz 命令上传字体时,定位到 windows 的 Fonts 目录,提示无权限。

  • 我们可以事先准备好所有中文字体,如下,在设计用于列,倒排序,复制所有简体中文字体到非系统目录,上传的时候方便全部上传。

  • 在 CentOS7 上,以 root 身份安装 fontconfig yum -y install fontconfig

  • 创建中文字体目录 mkdir -p /usr/share/fonts/chinese
  • 然后上传刚才准备好的字体文件到 /usr/share/fonts/chinese
  • 安装 ttmkfdir yum -y install ttmkfdir(注:这一步不确定是否必要,todo:下次再配置服务器先跳过这一步)

安装之后,跳过了网上教程的后续步骤,试着转换了一个 ppt 到 pdf,中文全都正常。

为了确定这样的中文安装步骤可以正常工作,于是将中文目录的中文字体移到别的目录,再次转换同样的 ppt,结果得到的 pdf 文件的中文字体全部变成方框了,于是再把中文字体移回/usr/share/fonts/chinese,再次转换,中文正常。

那么,安装中文字体就算成功了。

fc-list 检测

/usr/share/fonts/chinese/ 目录下的中文字体都列出来了,再一次证明中文字体安装正确,结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[root@ebs-60027 lib64]# fc-list
/usr/share/fonts/chinese/stxingka.ttf: STXingkai:style=Regular
/usr/share/fonts/chinese/幼圆.ttf: YouYuan:style=Regular
/usr/share/fonts/dejavu/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
/usr/share/fonts/chinese/msyh.ttc: Microsoft YaHei:style=Normal
/usr/share/fonts/dejavu/DejaVuSansCondensed-Bold.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold
/usr/share/fonts/chinese/stxihei.ttf: STXihei:style=Regular
/usr/share/fonts/chinese/simsun.ttc: SimSun,宋体:style=Regular,常规
/usr/share/fonts/chinese/msyhbd.ttc: Microsoft YaHei:style=Έντονα
/usr/share/fonts/chinese/stkaiti.ttf: STKaiti:style=Regular
/usr/share/fonts/chinese/Dengl.ttf: DengXian,DengXian Light:style=Light,Regular
/usr/share/fonts/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
/usr/share/fonts/chinese/Deng.ttf: DengXian:style=Regular
/usr/share/fonts/chinese/msyh.ttc: Microsoft YaHei UI:style=Normal
/usr/share/fonts/chinese/fzstk.ttf: FZShuTi:style=Regular
/usr/share/fonts/chinese/msyhbd.ttc: Microsoft YaHei UI:style=Έντονα
/usr/share/fonts/chinese/stfangso.ttf: STFangsong:style=Regular
/usr/share/fonts/chinese/Dengb.ttf: DengXian:style=Bold
/usr/share/fonts/chinese/stcaiyun.ttf: STCaiyun:style=Regular
/usr/share/fonts/chinese/simsun.ttc: NSimSun,新宋体:style=Regular,常规
/usr/share/fonts/chinese/msyhl.ttc: Microsoft YaHei UI,Microsoft YaHei UI Light:style=Light,Regular
/usr/share/fonts/chinese/simkai.ttf: KaiTi:style=Regular,Normaali
/usr/share/fonts/chinese/fzytk.ttf: FZYaoTi:style=Regular
/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold
/usr/share/fonts/chinese/stsong.ttf: STSong:style=Regular
/usr/share/fonts/chinese/sthupo.ttf: STHupo:style=Regular
/usr/share/fonts/chinese/simli.ttf: LiSu:style=Regular
/usr/share/fonts/chinese/stxinwei.ttf: STXinwei:style=Regular
/usr/share/fonts/chinese/stliti.ttf: STLiti:style=Regular
/usr/share/fonts/chinese/stzhongs.ttf: STZhongsong:style=Regular
/usr/share/fonts/dejavu/DejaVuSansCondensed.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book
/usr/share/fonts/dejavu/DejaVuSans-ExtraLight.ttf: DejaVu Sans,DejaVu Sans Light:style=ExtraLight
/usr/share/fonts/chinese/simsunb.ttf: SimSun\-ExtB:style=Regular,obyčejné
/usr/share/fonts/chinese/simhei.ttf: SimHei:style=Normal
/usr/share/fonts/dejavu/DejaVuSansCondensed-BoldOblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold Oblique,Bold Oblique
/usr/share/fonts/dejavu/DejaVuSans-Oblique.ttf: DejaVu Sans:style=Oblique
/usr/share/fonts/chinese/simfang.ttf: FangSong:style=Regular,Normaali
/usr/share/fonts/dejavu/DejaVuSans-BoldOblique.ttf: DejaVu Sans:style=Bold Oblique
/usr/share/fonts/chinese/msyhl.ttc: Microsoft YaHei,Microsoft YaHei Light:style=Light,Regular

windows 开发环境搭建

https://www.libreoffice.org/download/download/ 下载 .msi 版本直接安装,安装好后,将安装目录下的 program 目录添加到环境变量,在 windows 控制台执行:soffice -version,如果弹出一个新的控制台窗口显示版本信息,或者如下显示,说明安装配置已成功。

1
2
C:\Users\Andy>soffice --version
LibreOffice 6.4.0.3 b0a288ab3d2d4774cb44b62f04d5d28733ac6df8