47 Star 507 Fork 144

CastleCloud / docpreview

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

logo

CastleDocpreview 多文件在线预览

Gitee Stars JDK

如果你感觉这个项目不错,请点击右上角的Star以鼓励作者,谢谢。

文件在线预览模块(多格式转 PDF 文件)

说明:本项目是将一些常见的技术做了整合,帮助那些需要在线预览文件或正在寻找 office 转 pdf 文件预览的同学。如果你觉得本项目对你有帮助请点击一下 start,多谢大家!

2023新增说明: 《文档转换预览技术说明》:https://www.yuque.com/hcwdc/open/pos2lih1vi3248g9
已经将部分的教程进行了整合优化,放到了语雀的平台上,原先的老教程依然可以看。 基于这个技术做的知识库管理系统:https://gitee.com/hcwdc/knowledgebase

已经实现功能如下:

  • 多格式转换为 PDF 格式
  • OFFICE 转换为 PNG 格式
  • 在线预览文件
  • 手机预览查看文件

现已支持格式如下

  • 图片预览:.gif、bmp、jpeg、jpg、png、ico、svg
  • 文档预览:.doc、docx、xls、xlsx、ppt、pptx
  • PDF 文件:pdf、PDF 文件压缩
  • 文本文件:txt
  • 音频文件:mp3、ogg、wav
  • 视频文件:mp4、webm、mkv

在线演示地址

请勿上传重要的文件,该演示地址存储目录为临时目录,所有文件将会在每个月的月底进行全部删除。
本地启动后访问页面地址为:http://localhost:8301/index(还需修改参数配置或搭配Nginx使用)

运行方式

【必须】程序运行所在环境安装 LibreOffice,PDF 转换基于 LibreOffice 完成(OpenOffice 也一样可用)
安装参考教程:http://wiki.nooss.cn/archives/420.html
Linux 安装字体(不安装会出现乱码问题):http://wiki.nooss.cn/archives/406.html

  • 1、直接复制源码里的文件搬家至你自己的代码中
  • 2、将此 Demo 打包成为一个 jar 引入到自己的项目中

接口介绍

文件上传

http://ip:port/demo/upload

文件转 PDF

http://ip:port/demo/toPdf

文件转图片

ps:会先将文件转为 pdf,然后使用 pdfbox 转为图片

http://ip:port/demo/toPng

文件转SVG

ps:会先将文件转为 pdf,然后使用 pdfbox 转为svg

http://ip:port/demo/toSvg

参数配置

castle:
  upload:
    # 自行配置可访问的路径
    fileDomain: http://up.hcses.cn/pdftools  # 文件可访问的地址
    fileServerPath: /www/wwwroot/up.hcses.cn/pdftools/  # 原始文件的服务器存储位置

其他说明

项目关联关键词

word 转 pdf、word 转图片、office 格式转换、在线文件预览

前端预览弹出层用法

在页面 head 部分引入 <script src="preview.js"></script>

$Preview 参数

参数 说明
type 传入文件的粗类型 txt / img / pdf / mp3 / mp4
modal 所有打开的弹窗列表 Array<Modal>

$Preview 方法

show 打开弹窗
window.$Preview.show : (urls: string | Array<string>, options: Options) => $Preview

// e.g
window.$Preview.show('http://123.png')
window.$Preview.show(['http://123.png', 'http://456.png'])
window.$Preview.show(['http://123.png', 'http://456.png'], {
	active: 1
})

urls: Array<string> // 展示的文件地址列表
options: {
	active: number, // 打开时展示第几张 下标从 0 开始
}
closeAll 关闭所有弹窗
window.$Preview.closeAll : () => void
error 当解析文件路径错误时执行

暂时处理为 alert
可以根据需要自行覆盖

window.$Preview.error : (msg) => void

/**
 覆盖代理使用
 覆盖后 alert 将不再弹出
*/
window.$Preview.error = (msg) => {
	console.log(msg)
}
formatType 粗解析某个路径的文件格式
window.$Preview.formatType : (url: string) => 'txt' | 'img' | 'pdf' | 'mp3' | 'mp4'
formatShowType 返回某个路径的文件格式
window.$Preview.formatShowType : (url: string) => FileType
MIT License Copyright (c) 2021 CastleCloud Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

文件格式转换将多格式转换为pdf格式,转换为图片格式在进行预览展示。支持word 转 pdf、word 转图片等。 展开 收起
Java 等 4 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/hcwdc/docpreview.git
git@gitee.com:hcwdc/docpreview.git
hcwdc
docpreview
docpreview
master

搜索帮助

14c37bed 8189591 565d56ea 8189591