Electron2.x之后的版本都已经不支持PDF加载显示了,所以推荐网页中使用pdf.js
来加载PDF
允许加载域名不一样的资源
Nginx中允许资源跨域访问
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
viewer.js
中注释掉下面的这行
throw new Error("file origin does not match viewer's");
禁用工具条菜单
viewer.js
中webViewerInitialized()
方法最后添加
appConfig.toolbar.presentationModeButton.setAttribute('hidden', 'true');
appConfig.toolbar.openFile.setAttribute('hidden', 'true');
appConfig.toolbar.print.setAttribute('hidden', 'true');
appConfig.toolbar.download.setAttribute('hidden', 'true');
appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.toolbar.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.toolbarButtonContainer.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.presentationModeButton.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.printButton.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.firstPageButton.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.lastPageButton.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.pageRotateCwButton.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.pageRotateCcwButton.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.documentPropertiesButton.setAttribute('hidden', 'true');
访问方式
http://127.0.0.1:5500/web/viewer.html?file=https://www.psvmc.cn/123.pdf
修改后的资源下载地址
链接:https://pan.baidu.com/s/1cxhxFoumrxlEL1fk42x6IA 提取码:psvm
下载后直接放到项目的public目录下即可使用
项目中原来的地址修改为如下:
/pdf_show/web/viewer.html?file=https://www.psvmc.cn/123.pdf