kkFileView为文件文档在线预览解决方案,该项目使用流行的spring boot搭建,易上手和部署,基本支持主流办公文档的在线预览,如doc,docx,xls,xlsx,ppt,pptx,pdf,txt,zip,rar,图片,视频,音频等等
开源项目地址
https://gitee.com/kekingcn/file-online-preview
https://atengk.github.io/ops/#/work/docker/dockerfile/kkfileview/v4.4.0/
编译构建镜像时把开源赞助页去掉了,毕竟用在项目上,保留了官网主页。
镜像地址:registry.cn-hangzhou.aliyuncs.com/xglimage/kkfileview:v4.4.0-alpine
测试例子
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文件在线预览工具</title>
<!-- 引入Base64编码库 -->
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.6.0/base64.min.js"></script>
</head>
<body>
<header>
<h1>文件预览服务</h1>
<p>正在尝试打开文件预览...</p>
</header>
<script>
// 定义要预览的文件地址
var url = 'http://cephfiveview.youkext.com/test/test.xlsx';
// 构造预览URL
var previewUrl = 'http://10.0.0.72:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(url));
// 自动打开新窗口
window.open(previewUrl, '_blank');
</script>
<footer>
<p>© 2025 在线预览服务</p>
</footer>
</body>
</html>
内外端口不一致时nginx转发需要添加一个配置,否则docx等文件无法预览,加载不出图片
公网地址:http://kmfileview.test.com:8012
listen 80;
server_name kmfileview.test.com;
location / {
include proxy.conf;
proxy_pass http://10.221.5.79:8012;
proxy_set_header X-Base-Url http://kmfileview.test.com:8012;
}