文档在线预览和编辑免费版
一、kkfileview
version: '3' services: xbd-kkfileview: image: keking/kkfileview:4.1.0 restart: always container_name: xbd-kkfileview ports: - 8012:8012
二、onlyoffice
version: "3" services: xbd-mysql: image: mysql:8.0.19 restart: always container_name: xbd-mysql ports: - 3306:3306 volumes: - /var/lib/mysql/xbd-onlyoffice:/var/lib/mysql environment: - TZ=Asia/Shanghai - MYSQL_ROOT_PASSWORD=root privileged: true xbd-onlyoffice: image: onlyoffice/documentserver:7.2 restart: always container_name: xbd-onlyoffice ports: - 80:80 environment: - TZ=Asia/Shanghai - DB_TYPE=mysql - DB_HOST=xbd-mysql - DB_PORT=3306 - DB_NAME=onlyoffice - DB_USER=root - DB_PWD=root - JWT_ENABLED=false privileged: true depends_on: - xbd-mysql
备注:MySQL好了后,自建onlyoffice数据库,或者内置脚本也可以,参考https://www.cnblogs.com/ll409546297/p/16919642.html中的dockerfile的初始化方式。
权限:如果需要票据验证,则开启JWT_ENABLED(7.1后默认开启)和JWT_SECRET密钥
让后通过https://jwt.io/进行config的加密,最小为
{ "document": { "key": "xbd", "url": "http://192.168.5.1:8080/file/getFile" }, "editorConfig": { "callbackUrl": "http://192.168.5.1:8080/edit/save", "mode": "edit" } }
前端访问方式:加入token参数
1)前端编写
<!DOCTYPE html> <html style="height: 100%;"> <head> <title>打开DOCX进行编辑</title> </head> <body style="height: 100%; margin: 0;"> <div id="placeholder" style="height: 100%"></div> <script type="text/javascript" src="http://192.168.5.14/web-apps/apps/api/documents/api.js"></script> <script type="text/javascript"> window.docEditor = new DocsAPI.DocEditor("placeholder", { "document": { "fileType": "docx", "key": "xbd", "title": "Example Document Title.docx", "url": "http://192.168.5.1:8080/file/getFile" }, "documentType": "text", "editorConfig": { "callbackUrl": "http://192.168.5.1:8080/edit/save", "user": { "id": "xbd", "name": "xbd" }, "lang": "zh-CN", //语言 "mode": "edit"//模式 edit/view }, "height": "100%", "width": "100%" }); </script> </body> </html>
官方参考文档:https://api.onlyoffice.com/editors/try
官方参数说明:https://api.onlyoffice.com/editors/config/editor
2)后端
a、文件获取
@RestController @RequestMapping("/file") public class FileController { @GetMapping("/getFile") public void getFile(HttpServletResponse response) throws Exception { File file = new File("D:\\file\\1.docx"); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); response.setHeader("Content-Disposition", "attachment;filename=1.doc"); FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); } }
b、文件保存
@RestController @RequestMapping("/edit") public class EditController { @PostMapping("/save") public JSONObject save(@RequestBody JSONObject map) throws Exception { System.out.println(map); JSONObject jsonObject = new JSONObject(); jsonObject.put("error", "0"); Integer status = map.getInteger("status"); if (status.equals(2)) { UrlResource resource = new UrlResource(map.getString("url")); FileCopyUtils.copy(resource.getInputStream(), new FileOutputStream(new File("D:\\file\\1.docx"))); } return jsonObject; } }
备注:前端的KEY值,在后端保存一次,就需要更改,不然会出现版本问题。共同协作也是同理。
说明:文件保存的参数也有说明:主要注意状态2和异常状态。接口必须是post类型。参考地址:https://api.onlyoffice.com/editors/callback
开发过程中遇到的问题可以参考故障说明:https://api.onlyoffice.com/editors/troubleshooting
3、破解20限制,目前只发现5.3.4.3版本,通过修改容器里面的/var/www/onlyoffice/documentserver/server/Common/sources/constants.js即可实现
sed -i 's/exports.LICENSE_CONNECTIONS = 20/exports.LICENSE_CONNECTIONS = 100/g' /var/www/onlyoffice/documentserver/server/Common/sources/constants.js
4、破解20限制,7.3.2.8版本
1)有大神修改的版本限制300,通过拉取镜像可得:
docker pull frost1123/office:7.3.2.8
2)自己破解,主要是通过源码改写,这里不讲解,需要很久时间,网上有教程,主要是通过build_tools执行./automate.py server 来实现。
这里提供编译后的包后执行文件。
version: "3" services: xbd-mysql: image: mysql:8.0.19 restart: always container_name: xbd-mysql ports: - 3306:3306 volumes: - /var/lib/mysql/xbd-onlyoffice:/var/lib/mysql environment: - TZ=Asia/Shanghai - MYSQL_ROOT_PASSWORD=root privileged: true xbd-onlyoffice: build: context: ./ dockerfile: ./Dockerfile image: xbd/onlyoffice:7.3.2.8 restart: always container_name: xbd-onlyoffice ports: - 80:80 environment: - TZ=Asia/Shanghai - DB_TYPE=mysql - DB_HOST=xbd-mysql - DB_PORT=3306 - DB_NAME=onlyoffice - DB_USER=root - DB_PWD=root - JWT_ENABLED=false privileged: true depends_on: - xbd-mysql
Dockerfile
FROM onlyoffice/documentserver:7.3.2.8 COPY ./DocService/ /var/www/onlyoffice/documentserver/server/DocService/ COPY ./FileConverter/ /var/www/onlyoffice/documentserver/server/FileConverter/ COPY ./Fonts/ /usr/share/fonts/ CMD /usr/bin/documentserver-generate-allfonts.sh
文件下载地址:https://gitee.com/lilin409546297/onlyoffice 私有仓库不提供下载,有需要联系博主。