【update】pdf.js 禁用键盘打印和下载事件
This commit is contained in:
@@ -31,6 +31,11 @@ See https://github.com/adobe-type-tools/cmap-resources
|
||||
|
||||
<!-- This snippet is used in production (included from viewer.html) -->
|
||||
<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="viewer.js"></script>
|
||||
@@ -38,7 +43,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
||||
if (!window.frameElement) {
|
||||
// 禁用F12
|
||||
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()
|
||||
}
|
||||
})
|
||||
|
||||
+20
-19
@@ -788,9 +788,9 @@ const PDFViewerApplication = {
|
||||
},
|
||||
downloadOrSave() {
|
||||
if (this.pdfDocument?.annotationStorage.size > 0) {
|
||||
this.save();
|
||||
// this.save();
|
||||
} else {
|
||||
this.download();
|
||||
// this.download();
|
||||
}
|
||||
},
|
||||
_documentError(message, moreInfo = null) {
|
||||
@@ -1300,7 +1300,7 @@ const PDFViewerApplication = {
|
||||
if (!this.supportsPrinting) {
|
||||
return;
|
||||
}
|
||||
window.print();
|
||||
// window.print();
|
||||
},
|
||||
bindEvents() {
|
||||
const {
|
||||
@@ -1326,8 +1326,8 @@ const PDFViewerApplication = {
|
||||
eventBus._on("presentationmode", webViewerPresentationMode);
|
||||
eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
|
||||
eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
|
||||
eventBus._on("print", webViewerPrint);
|
||||
eventBus._on("download", webViewerDownload);
|
||||
// eventBus._on("print", webViewerPrint);
|
||||
// eventBus._on("download", webViewerDownload);
|
||||
eventBus._on("firstpage", webViewerFirstPage);
|
||||
eventBus._on("lastpage", webViewerLastPage);
|
||||
eventBus._on("nextpage", webViewerNextPage);
|
||||
@@ -1444,8 +1444,8 @@ const PDFViewerApplication = {
|
||||
eventBus._off("namedaction", webViewerNamedAction);
|
||||
eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
|
||||
eventBus._off("presentationmode", webViewerPresentationMode);
|
||||
eventBus._off("print", webViewerPrint);
|
||||
eventBus._off("download", webViewerDownload);
|
||||
// eventBus._off("print", webViewerPrint);
|
||||
// eventBus._off("download", webViewerDownload);
|
||||
eventBus._off("firstpage", webViewerFirstPage);
|
||||
eventBus._off("lastpage", webViewerLastPage);
|
||||
eventBus._off("nextpage", webViewerNextPage);
|
||||
@@ -1844,7 +1844,7 @@ function webViewerPrint() {
|
||||
PDFViewerApplication.triggerPrinting();
|
||||
}
|
||||
function webViewerDownload() {
|
||||
PDFViewerApplication.downloadOrSave();
|
||||
// PDFViewerApplication.downloadOrSave();
|
||||
}
|
||||
function webViewerFirstPage() {
|
||||
PDFViewerApplication.page = 1;
|
||||
@@ -2242,11 +2242,11 @@ function webViewerKeyDown(evt) {
|
||||
if (cmd === 1 || cmd === 8) {
|
||||
switch (evt.keyCode) {
|
||||
case 83:
|
||||
eventBus.dispatch("download", {
|
||||
source: window
|
||||
});
|
||||
handled = true;
|
||||
break;
|
||||
// eventBus.dispatch("download", {
|
||||
// source: window
|
||||
// });
|
||||
// handled = true;
|
||||
// break;
|
||||
case 79:
|
||||
{
|
||||
eventBus.dispatch("openfile", {
|
||||
@@ -13627,7 +13627,8 @@ function renderProgress(index, total, l10n) {
|
||||
}
|
||||
window.addEventListener("keydown", function (event) {
|
||||
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.stopImmediatePropagation();
|
||||
}
|
||||
@@ -13706,7 +13707,7 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) {
|
||||
/************************************************************************/
|
||||
/******/ // The module cache
|
||||
/******/ var __webpack_module_cache__ = {};
|
||||
/******/
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/ // Check if module is in cache
|
||||
@@ -13720,14 +13721,14 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) {
|
||||
/******/ // no module.loaded needed
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.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.
|
||||
@@ -13911,4 +13912,4 @@ if (document.readyState === "interactive" || document.readyState === "complete")
|
||||
|
||||
/******/ })()
|
||||
;
|
||||
//# sourceMappingURL=viewer.js.map
|
||||
//# sourceMappingURL=viewer.js.map
|
||||
|
||||
Reference in New Issue
Block a user