Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Recently, I need to have the function of online document viewing for my work project. At the beginning, I used the PDL. js of my old project, and later I also needed to use the mobile terminal. The documents uploaded by users also include Excel and PPT.

I found a circle on the Internet, and some brothers recommended kkFileView, so I tried it. Later proved to be really good!

1. KkFileView profile

Official website kkfileview.keking.cn/zh-cn/index…

KkFileView is a solution for online preview of file documents. The project uses popular Spring Boot to build, easy to get started and deploy, and basically supports online preview of mainstream office documents. Such as doc, docx, XLS, XLSX, PPT, PPTX, PDF, TXT, zip, rar, pictures, video, audio, etc

This is tempting from the introduction, as there is no need to do anything other than start a service.

2. Download the deployment file

Download address directly from the official website jump to the code cloud to download the latest, or directly to the code cloud to download gitee.com/kekingcn/fi…

Download the process just look at the official document, there are environmental requirements.

Take a look at all of them.

View the Java environment method start menu -> Run -> CMD -> Java -version

You can now see your local Java environment. If not, go to the official website to download the JDK installation.

At this time kkFileView in the installation package is also downloaded, decompressed files

Go to the startup script file in bin, right-click it, and run it as an administrator (on Linux, run startup.sh as user root).

After running, the following screenshot appears

Then our local browser accesses the native 8012 porthttp://127.0.0.1:8012

This local deployment is good, let’s test it in the project.

3. Project use

According to the method used in the documentation project, the code is as follows:

Var url = 'http://127.0.0.1:8080/file/test.txt'; / / to preview the file access address window. The open (' http://127.0.0.1:8012/onlinePreview? url='+encodeURIComponent(Base64.encode(url)));Copy the code

Two lines of code. Then try it on the mobile side. Done. Not only PPT, Excel support, even zip and other compressed files can be, it is too powerful. Excel is a little bit slower.

4. Process problems

4.1 Server Deployment

Our Server is Windows Server 2008. I thought that the system came with office and other plug-ins did not tube, and then run when the error has been reported. I took it for granted that I installed WPS separately, fixed office suite but failed, and finally downloaded LiberOffice.

4.2 Configuration File

The configuration file is application under Config. You can modify the port number, file upload size, watermark, etc. After modifying the port number, remember the corresponding port of the server to develop oh, at that time is to forget to open, engaged in a long time.

The online preview of the document is now easy, and there are many other powerful features waiting for XDM to discover.