參考: https://www.cnblogs.com/wuqilang/p/13031290.html
https://blog.csdn.net/qq_20473985/article/details/84984136
效果
1. 下載pdfjs
官網:http://mozilla.github.io/pdf.js/getting_started/#download
2. 放入項目中
將下載下來的文件解壓縮后,將里面的pdf文件夾拷貝到項目中的public文件夾中
3. 頁面中使用
window.open('/pdf/web/viewer.html?file=' + path);//path是文件的全路徑地址
4. 出現的問題
過程中,出現了一次報錯 "file origin does not match viewer's"
原因:跨域
解決方法: 直接注釋掉web/viewer.js中的1564到1566這幾行,不去判斷跨域即可
if (origin !== viewerOrigin && protocol !== 'blob:') { throw new Error('file origin does not match viewer\'s'); }