KKFileView realizes online preview of files

KKFileView is built using the popular spring boot, easy to use and deploy, and basically supports online preview of mainstream office documents, such as doc, docx, Excel, pdf, txt, zip, rar, pictures, etc.

Project features:

  1. Support word excel ppt, pdf and other office documents
  2. Support all plain texts such as txt, java, php, py, md, js, css, etc.
  3. Support zip, rar, jar, tar, gzip and other compressed packages
  4. Support jpg, jpeg, png, gif and other picture previews (flip, zoom, mirror)
  5. Support mp3, mp4, flv and other multimedia file preview
  6. Using spring boot development, preview service is very easy to build and deploy
  7. The rest interface provides services, and cross-platform features (java, php, python, go, php,...) are all supported, and application access is simple and convenient
  8. Supports multiple preview sources such as normal http/https file download url, http/https file download stream url, ftp download url, etc.
  9. Provide zip, tar.gz distribution package, provide one-click startup script and rich configuration items, easy to deploy and use
  10. Provide Docker image distribution package for easy deployment in container environment
  11. Abstract preview service interface, convenient for secondary development, very convenient to add other types of file preview support
  12. The most important thing is that the Apache protocol is open source, what you want to do when you pull the code

Official website address: KKFileView

This tutorial uses Centos to build KKFileView to realize the function of online preview of various attachments.

1 build

1 Go to the official website to download kkFileView-2.2.1.tar.gz

2 After uploading to the linux server, decompress and run (ps: download and install openOffice on the Internet, if the server does not have a network, you need to manually install and then modify the configuration files)

3 Since most Linux servers do not have Chinese fonts installed, the generated documents will have Chinese garbled characters. Therefore, we need to install Chinese fonts in Linux. The specific operations are as follows:

Download: After fonts.zip , put it into /usr/share/fonts and decompress it, and then execute the mkfontscale, mkfontdir, and fc-cache three commands. If these three commands are not available, yum installation is required (ps I heard that the server needs to be restarted after changing the font Will take effect later)

yum install mkfontscale
yum install fontconfig

If no effect after the restart, the / usr / share / fonts following font executable file instead chmod 755 *.ttf
then mkfontscale mkfontdir, fc-cahce rebootrestart

2 Use

The preview function must be implemented first, and there must be a file download interface on the backend

@ApiOperation("下载在线附件接口")
@GetMapping("/watch/{fileId}/{fileName}") 
//filename虽然在在里没有用到,当必须要有,因为kkfile通过fileName判断文件类型进而转换文件的
//filename的格式示例:aa.doc, aa.html, aa.txt, aa.pdf .....
public void watch(@ApiParam("文件id")@PathVariable String fileId, HttpServletResponse response) throws IOException {
    
    
    systemFileController.downloadFile(fileId,response);
}

3 Realize online preview of files by accessing kkFileView:

http://ip:port/onlinePreview?url=http://192.168.1.134:9746/watch/297446455118008320/test.docx&watermarkTxt=watermark to be added

For the time being, I only study it here, and I will continue to add it later.

Guess you like

Origin blog.csdn.net/dndndnnffj/article/details/112000034