1. 环境要求
- Java: 1.8+
- OpenOffice或LiberOffice(Windows下已内置,CentOS或Ubuntu下会自动下载安装,MacOS下需要自行安装)
2. 部署运行
1). 物理机或虚拟机上运行
- 从 码云发行版本 下载最新版发行包
- 解压kkFileView-x.x.x文件(Windows用.zip包,Linux/MacOS用.tar.gz包)
- 打开解压后文件夹的bin目录,运行startup脚本(Windows下以管理员身份运行
startup.bat
,Linux以root用户运行startup.sh
) - 浏览器访问本机8012端口 http://127.0.0.1:8012 即可看到项目演示用首页
2). Docker容器环境环境运行 #
- 拉取镜像
docker pull keking/kkfileview
- 运行
docker run -it -p 8012:8012 keking/kkfileview
- 浏览器访问容器8012端口
http://xxx.xxx.xxx.xxx:8012
即可看到项目演示用首页
3. 项目接入使用
当您的项目内需要预览文件时,只需要调用浏览器打开本项目的预览接口,并传入须要预览文件的url,示例如下:
3.x.x 及以上版本
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/js-base64@3.6.0/base64.min.js"></script>
var url = 'http://127.0.0.1:8080/file/test.txt'; //要预览文件的访问地址
window.open('http://127.0.0.1:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(previewUrl)));
2.x.x 及以下版本
var url = 'http://127.0.0.1:8080/file/test.txt'; //要预览文件的访问地址
window.open('http://127.0.0.1:8012/onlinePreview?url='+encodeURIComponent(previewUrl));
以上是官网的部署指南,在本地windows环境测试了一次
1、启动bin目录下的startup.bat(直接双击不行的话,就在目录下启动管理员cmd,输入startup.bat即可)
2、访问http://192.168.0.xx:8012/index
上传文件后,预览成功!
注意:有些环境的OpenOffice是没有的,自己去下载一个
链接:https://pan.baidu.com/s/1fzvMx9yQ2dHsxWwM6nUOWQ
提取码:g66h
然后将kkFileView\config目录下的application.properties文件修改一下
这样就可以启动成功了。
启动成功的日志可以在kkFileView-4.0.0\log下查看
_ _ ______ _ _ __ __ _
| | | | | ____| (_) | | \ \ / / (_)
| | __ | | __ | |__ _ | | ___ \ \ / / _ ___ __ __
| |/ / | |/ / | __| | | | | / _ \ \ \/ / | | / _ \ \ \ /\ / /
| < | < | | | | | | | __/ \ / | | | __/ \ V V /
|_|\_\ |_|\_\ |_| |_| |_| \___| \/ |_| \___| \_/\_/
=> Spring Boot :: (v2.4.2) QQ1 :: 613025121
=> kkFileView :: (v4.0.0) QQ2 :: 484680571
=> github :: https://github.com/kekingcn/kkFileView
=> gitee :: https://gitee.com/kekingcn/file-online-preview
2022-03-02 09:55:34.461 INFO 81252 --- [ main] org.eclipse.jetty.util.log : Logging initialized @2698ms to org.eclipse.jetty.util.log.Slf4jLog
2022-03-02 09:55:34.960 INFO 81252 --- [ main] o.s.b.w.e.j.JettyServletWebServerFactory : Server initialized with port: 8012
2022-03-02 09:55:34.963 INFO 81252 --- [ main] org.eclipse.jetty.server.Server : jetty-9.4.35.v20201120; built: 2020-11-20T21:17:03.964Z; git: bdc54f03a5e0a7e280fab27f55c3c75ee8da89fb; jvm 1.8.0_201-b09
2022-03-02 09:55:34.995 INFO 81252 --- [ main] o.e.j.s.h.ContextHandler.application : Initializing Spring embedded WebApplicationContext
2022-03-02 09:55:34.996 INFO 81252 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2028 ms
2022-03-02 09:55:35.182 INFO 81252 --- [ main] org.eclipse.jetty.server.session : DefaultSessionIdManager workerName=node0
2022-03-02 09:55:35.182 INFO 81252 --- [ main] org.eclipse.jetty.server.session : No SessionScavenger set, using defaults
2022-03-02 09:55:35.183 INFO 81252 --- [ main] org.eclipse.jetty.server.session : node0 Scavenging every 600000ms
2022-03-02 09:55:35.190 INFO 81252 --- [ main] o.e.jetty.server.handler.ContextHandler : Started o.s.b.w.e.j.JettyEmbeddedWebAppContext@7fa98a66{application,/,[file:///C:/Users/PC/AppData/Local/Temp/jetty-docbase.8012.8310360477068667296/],AVAILABLE}
2022-03-02 09:55:35.190 INFO 81252 --- [ main] org.eclipse.jetty.server.Server : Started @3428ms
2022-03-02 09:55:35.205 INFO 81252 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static methods: public static void cn.keking.config.ConfigConstants.setFileUploadDisable(java.lang.Boolean)
2022-03-02 09:55:35.308 INFO 81252 --- [ main] cn.keking.service.FileConvertQueueTask : 队列处理文件转换任务启动完成
2022-03-02 09:55:36.251 INFO 81252 --- [ main] o.a.j.office.ProcessPoolOfficeManager : ProcessManager implementation is PureJavaProcessManager
2022-03-02 09:55:36.254 INFO 81252 --- [ProcessThread-0] o.a.jodconverter.office.OfficeProcess : starting process with acceptString 'socket,host=127.0.0.1,port=2001,tcpNoDelay=1' and profileDir 'C:\Users\PC\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-2001'
2022-03-02 09:55:36.410 INFO 81252 --- [ProcessThread-0] o.a.jodconverter.office.OfficeProcess : started process
2022-03-02 09:55:40.820 WARN 81252 --- [ProcessThread-0] o.a.j.office.ManagedOfficeProcess : office process died with exit code 81; restarting it
2022-03-02 09:55:40.820 INFO 81252 --- [ProcessThread-0] o.a.jodconverter.office.OfficeProcess : starting process with acceptString 'socket,host=127.0.0.1,port=2001,tcpNoDelay=1' and profileDir 'C:\Users\PC\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-2001'
2022-03-02 09:55:40.839 INFO 81252 --- [ProcessThread-0] o.a.jodconverter.office.OfficeProcess : started process
2022-03-02 09:55:45.127 INFO 81252 --- [ProcessThread-0] o.a.j.office.OfficeConnection : connected: 'socket,host=127.0.0.1,port=2001,tcpNoDelay=1'
2022-03-02 09:55:45.129 INFO 81252 --- [ProcessThread-1] o.a.jodconverter.office.OfficeProcess : starting process with acceptString 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1' and profileDir 'C:\Users\PC\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-2002'
2022-03-02 09:55:45.146 INFO 81252 --- [ProcessThread-1] o.a.jodconverter.office.OfficeProcess : started process
2022-03-02 09:55:47.174 WARN 81252 --- [ProcessThread-1] o.a.j.office.ManagedOfficeProcess : office process died with exit code 81; restarting it
2022-03-02 09:55:47.175 INFO 81252 --- [ProcessThread-1] o.a.jodconverter.office.OfficeProcess : starting process with acceptString 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1' and profileDir 'C:\Users\PC\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-2002'
2022-03-02 09:55:47.207 INFO 81252 --- [ProcessThread-1] o.a.jodconverter.office.OfficeProcess : started process
2022-03-02 09:55:49.527 INFO 81252 --- [ProcessThread-1] o.a.j.office.OfficeConnection : connected: 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1'
2022-03-02 09:55:50.358 INFO 81252 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2022-03-02 09:55:50.514 INFO 81252 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2022-03-02 09:55:50.550 INFO 81252 --- [ main] cn.keking.config.WebConfig : Add resource locations: D:\kkFileView-4.0.0\file\
2022-03-02 09:55:51.181 INFO 81252 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2022-03-02 09:55:51.234 INFO 81252 --- [ main] o.e.j.s.h.ContextHandler.application : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-03-02 09:55:51.234 INFO 81252 --- [ main] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-03-02 09:55:51.235 INFO 81252 --- [ main] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2022-03-02 09:55:51.283 INFO 81252 --- [ main] o.e.jetty.server.AbstractConnector : Started ServerConnector@bef2d72{HTTP/1.1, (http/1.1)}{0.0.0.0:8012}
2022-03-02 09:55:51.284 INFO 81252 --- [ main] o.s.b.web.embedded.jetty.JettyWebServer : Jetty started on port(s) 8012 (http/1.1) with context path '/'
2022-03-02 09:55:51.324 INFO 81252 --- [ main] cn.keking.ServerMain : kkFileView 服务启动完成,耗时:19.208754s,演示页请访问: http://127.0.0.1:8012
2022-03-02 09:57:01.536 INFO 81252 --- [tp1196695891-19] cn.keking.web.controller.FileController : 删除文件:D:\kkFileView-4.0.0\file\demo\20211029 四川省自然资源中介机构管理开发计划.xlsx
2022-03-02 10:03:52.570 INFO 81252 --- [tp1196695891-21] cn.keking.web.controller.FileController : 上传文件:D:\kkFileView-4.0.0\file\demo\社保缴纳证明3.PNG
2022-03-02 10:04:13.278 INFO 81252 --- [tp1196695891-18] c.k.w.c.OnlinePreviewController : 预览文件url:http://192.168.0.123:8012/demo/社保缴纳证明3.PNG,previewType:PICTURE
一个简单的文件预览测试html
<html>
<head>
<title>我的第一个 HTML 页面</title>
</head>
<body>
<p>body 元素的内容会显示在浏览器中。</p>
<button onclick="changetext()">点击</button>
</body>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/js-base64@3.6.0/base64.min.js"></script>
<script>
var url = 'http://192.168.0.123:9000/file/四川xxx有限公司/null/2021130xxxx评论会议.docx';
function changetext(){
window.open('http://192.168.0.123:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(url)));
}
</script>
</html>