linux 使用kkFileView组件实现在线文件预览

发布时间 2023-07-20 15:58:09作者: 快乐小洋人

kkFileView简介

此项目为文件文档在线预览项目解决方案,对标业内付费产品有【永中office】【office365】【idocv】等,在取得公司高层同意后以Apache协议开源出来反哺社区,该项目使用流行的spring boot搭建,易上手和部署,基本支持主流办公文档的在线预览,如doc,docx,Excel,pdf,txt,zip,rar,图片等等。具体参考官方文档:https://kkfileview.keking.cn/zh-cn/docs/home.html

kkFileView 安装

环境要求

  • Java: 1.8+
  • LibreOffice或OpenOffice(Windows下已内置,CentOS或Ubuntu下会自动下载安装,MacOS下需要自行安装)

linux安装LibreOffice或OpenOffice

LibreOffice

下载地址:https://zh-cn.libreoffice.org/download/libreoffice/

OpenOffice

下载地址:http://www.openoffice.org/zh-cn/download/

随便下载一个,我这里下载的是LibreOffice,兼容性更好点

安装

#安装openoffice
 
[root@cql ~]# tar -xf Apache_OpenOffice_4.1.5_Linux_x86-64_install-rpm_zh-CN.tar.gz
 
[root@cql zh-CN]# cd RPMS/
[root@cql RPMS]# rpm -ivh *.rpm
 
[root@cql zh-CN]# desktop-integration/
[root@cql desktop-integration]# rpm -ivh openoffice4.1.5-redhat-menus-4.1.5-9789.noarch.rpm
 
[root@cql RPMS] yum groupinstall "X Window System"
 
报错:
SyntaxError: invalid syntax
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
解决办法:
由于升级过python版本,修改/usr/libexec/urlgrabber-ext-down和/usr/bin/yum的python解释器版本
 
启动:
[root@cql desktop-integration]# /opt/openoffice4/program/soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard &
[1] 57754
[root@cql desktop-integration]# ps aux | grep 57754
root     57754  0.0  0.3 113132   752 pts/0    S    09:39   0:00 /bin/sh /opt/openoffice4/program/soffice --headless --accept=socket,host=127.0.0.1,port=8100;urp; --nofirststartwizard
root     57801  0.0  0.2 112680   696 pts/0    R+   09:40   0:00 grep --color=auto 57754
 
 
#安装libreoffice
[root@www tools]# tar -xvf LibreOffice_6.0.5.2_Linux_x86-64_rpm.tar.gz -C /opt
[root@www tools]# tar -xf LibreOffice_6.0.5.2_Linux_x86-64_rpm_langpack_zh-CN.tar.gz -C /opt
 
[root@www opt]# cd /opt/LibreOffice_6.0.5.2_Linux_x86-64_rpm/RPMS
[root@www RPMS]# yum localinstall *.rpm
[root@www opt]# cd /opt/LibreOffice_6.0.5.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS
[root@www RPMS]# yum localinstall *.rpm
 
/opt/libreoffice6.0/program/soffice --headless --accept='socket,host=127.0.0.1,port=8100;urp;' --nofirststartwizard &
 
#设置开机重自启动直接将上面的启动命令写入/etc/rc.d/rc.local文件中
#如果出现中文乱码的情况,首先关注在libreoffice的安装目录下的fonts目录下有没有简体中文的字体文件
#然后去看系统目录下/usr/share/fonts下有没有简体中文的字体文件

#使用rpma安装安装包时,会出现error: Failed dependencies:意思是 失败的依赖 
#解决:在安装包后面加两个参数,如:rpm -ivh 包名 --nodeps --force,加上那两个参数的意义就在于,安装时不再分析包之间的依赖关系而直接安装

安装字体

1.下载中文字体包

http://kkfileview.keking.cn/fonts.zip

2.文件解压完整拷贝到Linux下的 /usr/share/fonts目录。

3.然后依次执行mkfontscale 、mkfontdir 、fc-cache使字体生效

如果报错命令没有找到,则安装对应命令,例如:yum install -y mkfontscale

4.赋予字体权限

chmod -R 755 *.TTF
chmod -R 755 *.ttf
chmod -R 755 *.ttc

5.使配置生效 source /etc/profile

6.将之前kkfileview服务和office服务都停止
ps -ef | grep soffice

7.重启 kkfilleview(kkfileview服务会启动office)

kkFileView 代码问题配置

码云地址:https://gitee.com/kekingcn/file-online-preview

配置文件目录:

1.配置了nginx代理需要配置 server.servlet.context-path,不要忘了代理路径配置正确

2.配置缓存文件生成目录file.dir

3.如果不想使用base64加密,注释代码:

4.部署到linux配置文件访问报错,设置配置文件从外部加载:

此时加载配置路径为:/home/office/config/application.properties


原文章地址:
https://blog.csdn.net/cql08e/article/details/81234521
https://tech99.cn/shot/?uuid=CSDN_129188399