SpringBoot+Thymeleaf使用pdfjs 实现对pdf文件的预览
首先贴上pdfjs的github地址:pdfjs-dist下载地址
当你下载解压之后出现的内容:
然后,将其添加到项目的/static文件夹下
然后在进行**修改view.js**中的默认打开的pdf文件为空字符串(防止用户在不传file值得时候打开)
上图中的compressed.tracemonkey-pldi-09.pdf就是会默认打开的pdf文件
之后在html页面中配置使用
//查看pdf文件模态框显示
function toViewFile(object) {
//文件的路径
let idVal = object.title;
//对通知的数据进行查询并回显
$("#viewPdfIframe").attr('src','/plugins/pdfjs-2.7.570-dist/web/viewer.html?file=' +
encodeURIComponent('http://localhost:8080/file/previewPdf?UUID=' + idVal));
$("#viewFilePdf").modal({
backdrop: "static"
});
}
对应的控件: