【update】pdf.js 禁用键盘打印和下载事件

This commit is contained in:
fengchenchen
2024-08-08 15:31:12 +08:00
parent d8bf730655
commit c3896a2569
2 changed files with 26 additions and 20 deletions
+6 -1
View File
@@ -31,6 +31,11 @@ See https://github.com/adobe-type-tools/cmap-resources
<!-- This snippet is used in production (included from viewer.html) --> <!-- This snippet is used in production (included from viewer.html) -->
<link rel="resource" type="application/l10n" href="locale/locale.properties"> <link rel="resource" type="application/l10n" href="locale/locale.properties">
<style>
@media print {
body {display: none}
}
</style>
<script src="../build/pdf.js"></script> <script src="../build/pdf.js"></script>
<script src="viewer.js"></script> <script src="viewer.js"></script>
@@ -38,7 +43,7 @@ See https://github.com/adobe-type-tools/cmap-resources
if (!window.frameElement) { if (!window.frameElement) {
// 禁用F12 // 禁用F12
document.addEventListener('keydown', function(event) { document.addEventListener('keydown', function(event) {
if (event.key === 'F12' || event.keyCode === 123) { if (event.key === 'F12' || event.keyCode === 123 || event.code === 'KeyS' || event.code === 'KeyP') {
event.preventDefault() event.preventDefault()
} }
}) })
+20 -19
View File
@@ -788,9 +788,9 @@ const PDFViewerApplication = {
}, },
downloadOrSave() { downloadOrSave() {
if (this.pdfDocument?.annotationStorage.size > 0) { if (this.pdfDocument?.annotationStorage.size > 0) {
this.save(); // this.save();
} else { } else {
this.download(); // this.download();
} }
}, },
_documentError(message, moreInfo = null) { _documentError(message, moreInfo = null) {
@@ -1300,7 +1300,7 @@ const PDFViewerApplication = {
if (!this.supportsPrinting) { if (!this.supportsPrinting) {
return; return;
} }
window.print(); // window.print();
}, },
bindEvents() { bindEvents() {
const { const {
@@ -1326,8 +1326,8 @@ const PDFViewerApplication = {
eventBus._on("presentationmode", webViewerPresentationMode); eventBus._on("presentationmode", webViewerPresentationMode);
eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode); eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams); eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
eventBus._on("print", webViewerPrint); // eventBus._on("print", webViewerPrint);
eventBus._on("download", webViewerDownload); // eventBus._on("download", webViewerDownload);
eventBus._on("firstpage", webViewerFirstPage); eventBus._on("firstpage", webViewerFirstPage);
eventBus._on("lastpage", webViewerLastPage); eventBus._on("lastpage", webViewerLastPage);
eventBus._on("nextpage", webViewerNextPage); eventBus._on("nextpage", webViewerNextPage);
@@ -1444,8 +1444,8 @@ const PDFViewerApplication = {
eventBus._off("namedaction", webViewerNamedAction); eventBus._off("namedaction", webViewerNamedAction);
eventBus._off("presentationmodechanged", webViewerPresentationModeChanged); eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
eventBus._off("presentationmode", webViewerPresentationMode); eventBus._off("presentationmode", webViewerPresentationMode);
eventBus._off("print", webViewerPrint); // eventBus._off("print", webViewerPrint);
eventBus._off("download", webViewerDownload); // eventBus._off("download", webViewerDownload);
eventBus._off("firstpage", webViewerFirstPage); eventBus._off("firstpage", webViewerFirstPage);
eventBus._off("lastpage", webViewerLastPage); eventBus._off("lastpage", webViewerLastPage);
eventBus._off("nextpage", webViewerNextPage); eventBus._off("nextpage", webViewerNextPage);
@@ -1844,7 +1844,7 @@ function webViewerPrint() {
PDFViewerApplication.triggerPrinting(); PDFViewerApplication.triggerPrinting();
} }
function webViewerDownload() { function webViewerDownload() {
PDFViewerApplication.downloadOrSave(); // PDFViewerApplication.downloadOrSave();
} }
function webViewerFirstPage() { function webViewerFirstPage() {
PDFViewerApplication.page = 1; PDFViewerApplication.page = 1;
@@ -2242,11 +2242,11 @@ function webViewerKeyDown(evt) {
if (cmd === 1 || cmd === 8) { if (cmd === 1 || cmd === 8) {
switch (evt.keyCode) { switch (evt.keyCode) {
case 83: case 83:
eventBus.dispatch("download", { // eventBus.dispatch("download", {
source: window // source: window
}); // });
handled = true; // handled = true;
break; // break;
case 79: case 79:
{ {
eventBus.dispatch("openfile", { eventBus.dispatch("openfile", {
@@ -13627,7 +13627,8 @@ function renderProgress(index, total, l10n) {
} }
window.addEventListener("keydown", function (event) { window.addEventListener("keydown", function (event) {
if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) { if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
window.print(); // window.print();
return false
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation(); event.stopImmediatePropagation();
} }
@@ -13706,7 +13707,7 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) {
/************************************************************************/ /************************************************************************/
/******/ // The module cache /******/ // The module cache
/******/ var __webpack_module_cache__ = {}; /******/ var __webpack_module_cache__ = {};
/******/ /******/
/******/ // The require function /******/ // The require function
/******/ function __webpack_require__(moduleId) { /******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache /******/ // Check if module is in cache
@@ -13720,14 +13721,14 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) {
/******/ // no module.loaded needed /******/ // no module.loaded needed
/******/ exports: {} /******/ exports: {}
/******/ }; /******/ };
/******/ /******/
/******/ // Execute the module function /******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ /******/
/******/ // Return the exports of the module /******/ // Return the exports of the module
/******/ return module.exports; /******/ return module.exports;
/******/ } /******/ }
/******/ /******/
/************************************************************************/ /************************************************************************/
var __webpack_exports__ = {}; var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
@@ -13911,4 +13912,4 @@ if (document.readyState === "interactive" || document.readyState === "complete")
/******/ })() /******/ })()
; ;
//# sourceMappingURL=viewer.js.map //# sourceMappingURL=viewer.js.map