pdfjs-dist 2.6.347 → 2.7.570
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/README.md +3 -3
- package/bower.json +1 -1
- package/build/pdf.js +2050 -1087
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +18219 -10436
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/es5/build/pdf.d.ts +1 -0
- package/es5/build/pdf.js +6623 -6654
- package/es5/build/pdf.js.map +1 -1
- package/es5/build/pdf.min.js +1 -1
- package/es5/build/pdf.worker.js +20815 -13888
- package/es5/build/pdf.worker.js.map +1 -1
- package/es5/build/pdf.worker.min.js +1 -1
- package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
- package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
- package/es5/web/pdf_viewer.css +18 -15
- package/es5/web/pdf_viewer.js +1094 -514
- package/es5/web/pdf_viewer.js.map +1 -1
- package/image_decoders/pdf.image_decoders.js +774 -168
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +1 -1
- package/lib/core/annotation.js +556 -108
- package/lib/core/cff_parser.js +7 -1
- package/lib/core/charsets.js +1 -1
- package/lib/core/cmap.js +20 -1
- package/lib/core/core_utils.js +162 -3
- package/lib/core/crypto.js +1 -1
- package/lib/core/default_appearance.js +132 -0
- package/lib/core/document.js +115 -9
- package/lib/core/encodings.js +1 -1
- package/lib/core/evaluator.js +168 -74
- package/lib/core/fonts.js +97 -11
- package/lib/core/function.js +5 -10
- package/lib/core/glyphlist.js +11 -4529
- package/lib/core/image_utils.js +30 -1
- package/lib/core/jpg.js +1 -1
- package/lib/core/jpx.js +5 -5
- package/lib/core/murmurhash3.js +1 -1
- package/lib/core/obj.js +123 -39
- package/lib/core/pattern.js +4 -4
- package/lib/core/primitives.js +24 -5
- package/lib/core/standard_fonts.js +1 -1
- package/lib/core/stream.js +5 -1
- package/lib/core/unicode.js +15 -1387
- package/lib/core/worker.js +58 -17
- package/lib/core/writer.js +68 -4
- package/lib/display/annotation_layer.js +712 -119
- package/lib/display/annotation_storage.js +21 -4
- package/lib/display/api.js +88 -18
- package/lib/display/canvas.js +414 -375
- package/lib/display/display_utils.js +11 -4
- package/lib/display/fetch_stream.js +3 -3
- package/lib/display/font_loader.js +2 -3
- package/lib/display/metadata.js +54 -20
- package/lib/display/node_stream.js +1 -1
- package/lib/display/optional_content_config.js +1 -1
- package/lib/display/pattern_helper.js +109 -113
- package/lib/display/svg.js +5 -5
- package/lib/display/text_layer.js +54 -54
- package/lib/display/transport_stream.js +4 -4
- package/lib/display/webgl.js +65 -68
- package/lib/examples/node/domstubs.js +9 -4
- package/lib/pdf.js +2 -2
- package/lib/pdf.sandbox.js +311 -0
- package/lib/pdf.worker.js +2 -2
- package/lib/shared/scripting_utils.js +84 -0
- package/lib/shared/util.js +129 -14
- package/lib/{display → shared}/xml_parser.js +112 -4
- package/lib/test/unit/annotation_spec.js +831 -109
- package/lib/test/unit/annotation_storage_spec.js +28 -10
- package/lib/test/unit/api_spec.js +190 -160
- package/lib/test/unit/bidi_spec.js +6 -6
- package/lib/test/unit/cff_parser_spec.js +73 -73
- package/lib/test/unit/clitests_helper.js +2 -0
- package/lib/test/unit/cmap_spec.js +48 -74
- package/lib/test/unit/core_utils_spec.js +34 -0
- package/lib/test/unit/crypto_spec.js +162 -199
- package/lib/test/unit/custom_spec.js +7 -18
- package/lib/test/unit/default_appearance_spec.js +54 -0
- package/lib/test/unit/display_svg_spec.js +24 -19
- package/lib/test/unit/display_utils_spec.js +1 -1
- package/lib/test/unit/document_spec.js +187 -20
- package/lib/test/unit/evaluator_spec.js +30 -30
- package/lib/test/unit/function_spec.js +165 -165
- package/lib/test/unit/jasmine-boot.js +52 -53
- package/lib/test/unit/metadata_spec.js +2 -2
- package/lib/test/unit/murmurhash3_spec.js +29 -16
- package/lib/test/unit/network_spec.js +21 -21
- package/lib/test/unit/pdf_find_controller_spec.js +131 -69
- package/lib/test/unit/pdf_find_utils_spec.js +10 -10
- package/lib/test/unit/scripting_spec.js +1104 -0
- package/lib/test/unit/stream_spec.js +8 -8
- package/lib/test/unit/test_utils.js +16 -19
- package/lib/test/unit/testreporter.js +11 -4
- package/lib/test/unit/type1_parser_spec.js +23 -23
- package/lib/test/unit/ui_utils_spec.js +78 -35
- package/lib/test/unit/unicode_spec.js +7 -7
- package/lib/test/unit/util_spec.js +26 -3
- package/lib/test/unit/writer_spec.js +16 -1
- package/lib/test/unit/xml_spec.js +117 -0
- package/lib/web/annotation_layer_builder.js +18 -6
- package/lib/web/app.js +579 -161
- package/lib/web/app_options.js +14 -0
- package/lib/web/base_tree_viewer.js +50 -0
- package/lib/web/base_viewer.js +350 -14
- package/lib/web/chromecom.js +9 -1
- package/lib/web/debugger.js +1 -2
- package/lib/web/download_manager.js +0 -15
- package/lib/web/firefox_print_service.js +6 -4
- package/lib/web/firefoxcom.js +84 -69
- package/lib/web/generic_scripting.js +55 -0
- package/lib/web/genericcom.js +9 -1
- package/lib/web/grab_to_pan.js +1 -1
- package/lib/web/interfaces.js +9 -3
- package/lib/web/pdf_attachment_viewer.js +1 -3
- package/lib/web/pdf_cursor_tools.js +20 -13
- package/lib/web/pdf_document_properties.js +48 -61
- package/lib/web/pdf_find_bar.js +1 -3
- package/lib/web/pdf_find_controller.js +58 -12
- package/lib/web/pdf_history.js +43 -21
- package/lib/web/pdf_layer_viewer.js +1 -9
- package/lib/web/pdf_link_service.js +108 -78
- package/lib/web/pdf_outline_viewer.js +166 -10
- package/lib/web/pdf_page_view.js +14 -14
- package/lib/web/pdf_presentation_mode.js +21 -31
- package/lib/web/pdf_rendering_queue.js +8 -1
- package/lib/web/pdf_sidebar.js +62 -107
- package/lib/web/pdf_sidebar_resizer.js +11 -21
- package/lib/web/pdf_single_page_viewer.js +8 -0
- package/lib/web/pdf_thumbnail_view.js +26 -26
- package/lib/web/pdf_thumbnail_viewer.js +13 -2
- package/lib/web/pdf_viewer.component.js +2 -2
- package/lib/web/pdf_viewer.js +3 -1
- package/lib/web/preferences.js +33 -44
- package/lib/web/text_layer_builder.js +2 -9
- package/lib/web/ui_utils.js +78 -46
- package/lib/web/viewer_compatibility.js +1 -2
- package/package.json +4 -1
- package/types/display/annotation_layer.d.ts +18 -3
- package/types/display/api.d.ts +110 -54
- package/types/display/canvas.d.ts +1 -1
- package/types/display/display_utils.d.ts +96 -95
- package/types/display/fetch_stream.d.ts +2 -2
- package/types/display/metadata.d.ts +4 -0
- package/types/display/pattern_helper.d.ts +1 -1
- package/types/display/text_layer.d.ts +7 -7
- package/types/display/transport_stream.d.ts +1 -1
- package/types/shared/scripting_utils.d.ts +12 -0
- package/types/shared/util.d.ts +281 -250
- package/types/shared/xml_parser.d.ts +64 -0
- package/web/pdf_viewer.css +18 -15
- package/web/pdf_viewer.js +809 -408
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +1 -1
- package/types/display/xml_parser.d.ts +0 -35
package/lib/web/app.js
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.
|
27
|
+
exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
|
28
28
|
|
29
29
|
var _ui_utils = require("./ui_utils.js");
|
30
30
|
|
@@ -36,8 +36,6 @@ var _pdf_cursor_tools = require("./pdf_cursor_tools.js");
|
|
36
36
|
|
37
37
|
var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
|
38
38
|
|
39
|
-
var _pdf_sidebar = require("./pdf_sidebar.js");
|
40
|
-
|
41
39
|
var _overlay_manager = require("./overlay_manager.js");
|
42
40
|
|
43
41
|
var _password_prompt = require("./password_prompt.js");
|
@@ -60,6 +58,8 @@ var _pdf_outline_viewer = require("./pdf_outline_viewer.js");
|
|
60
58
|
|
61
59
|
var _pdf_presentation_mode = require("./pdf_presentation_mode.js");
|
62
60
|
|
61
|
+
var _pdf_sidebar = require("./pdf_sidebar.js");
|
62
|
+
|
63
63
|
var _pdf_sidebar_resizer = require("./pdf_sidebar_resizer.js");
|
64
64
|
|
65
65
|
var _pdf_thumbnail_viewer = require("./pdf_thumbnail_viewer.js");
|
@@ -84,6 +84,11 @@ const ViewOnLoad = {
|
|
84
84
|
PREVIOUS: 0,
|
85
85
|
INITIAL: 1
|
86
86
|
};
|
87
|
+
const ViewerCssTheme = {
|
88
|
+
AUTOMATIC: 0,
|
89
|
+
LIGHT: 1,
|
90
|
+
DARK: 2
|
91
|
+
};
|
87
92
|
const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
|
88
93
|
const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
|
89
94
|
|
@@ -98,7 +103,7 @@ class DefaultExternalServices {
|
|
98
103
|
|
99
104
|
static initPassiveLoading(callbacks) {}
|
100
105
|
|
101
|
-
static fallback(data
|
106
|
+
static async fallback(data) {}
|
102
107
|
|
103
108
|
static reportTelemetry(data) {}
|
104
109
|
|
@@ -114,6 +119,10 @@ class DefaultExternalServices {
|
|
114
119
|
throw new Error("Not implemented: createL10n");
|
115
120
|
}
|
116
121
|
|
122
|
+
static createScripting(options) {
|
123
|
+
throw new Error("Not implemented: createScripting");
|
124
|
+
}
|
125
|
+
|
117
126
|
static get supportsIntegratedFind() {
|
118
127
|
return (0, _pdf.shadow)(this, "supportsIntegratedFind", false);
|
119
128
|
}
|
@@ -171,17 +180,26 @@ const PDFViewerApplication = {
|
|
171
180
|
url: "",
|
172
181
|
baseUrl: "",
|
173
182
|
externalServices: DefaultExternalServices,
|
174
|
-
_boundEvents:
|
175
|
-
|
183
|
+
_boundEvents: Object.create(null),
|
184
|
+
documentInfo: null,
|
185
|
+
metadata: null,
|
186
|
+
_contentDispositionFilename: null,
|
187
|
+
_contentLength: null,
|
176
188
|
triggerDelayedFallback: null,
|
177
189
|
_saveInProgress: false,
|
178
190
|
_wheelUnusedTicks: 0,
|
191
|
+
_idleCallbacks: new Set(),
|
192
|
+
_scriptingInstance: null,
|
193
|
+
_mouseState: Object.create(null),
|
179
194
|
|
180
195
|
async initialize(appConfig) {
|
181
196
|
this.preferences = this.externalServices.createPreferences();
|
182
197
|
this.appConfig = appConfig;
|
183
198
|
await this._readPreferences();
|
184
199
|
await this._parseHashParameters();
|
200
|
+
|
201
|
+
this._forceCssTheme();
|
202
|
+
|
185
203
|
await this._initializeL10n();
|
186
204
|
|
187
205
|
if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf.LinkTarget.NONE) {
|
@@ -207,13 +225,9 @@ const PDFViewerApplication = {
|
|
207
225
|
}
|
208
226
|
|
209
227
|
try {
|
210
|
-
|
211
|
-
|
212
|
-
for (const name in prefs) {
|
213
|
-
_app_options.AppOptions.set(name, prefs[name]);
|
214
|
-
}
|
228
|
+
_app_options.AppOptions.setAll(await this.preferences.getAll());
|
215
229
|
} catch (reason) {
|
216
|
-
console.error(`_readPreferences: "${reason
|
230
|
+
console.error(`_readPreferences: "${reason?.message}".`);
|
217
231
|
}
|
218
232
|
},
|
219
233
|
|
@@ -292,6 +306,10 @@ const PDFViewerApplication = {
|
|
292
306
|
_app_options.AppOptions.set("locale", hashParams.locale);
|
293
307
|
}
|
294
308
|
|
309
|
+
if (waitOn.length === 0) {
|
310
|
+
return undefined;
|
311
|
+
}
|
312
|
+
|
295
313
|
return Promise.all(waitOn).catch(reason => {
|
296
314
|
console.error(`_parseHashParameters: "${reason.message}".`);
|
297
315
|
});
|
@@ -305,6 +323,41 @@ const PDFViewerApplication = {
|
|
305
323
|
document.getElementsByTagName("html")[0].dir = dir;
|
306
324
|
},
|
307
325
|
|
326
|
+
_forceCssTheme() {
|
327
|
+
const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
|
328
|
+
|
329
|
+
if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
|
330
|
+
return;
|
331
|
+
}
|
332
|
+
|
333
|
+
try {
|
334
|
+
const styleSheet = document.styleSheets[0];
|
335
|
+
const cssRules = styleSheet?.cssRules || [];
|
336
|
+
|
337
|
+
for (let i = 0, ii = cssRules.length; i < ii; i++) {
|
338
|
+
const rule = cssRules[i];
|
339
|
+
|
340
|
+
if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
|
341
|
+
if (cssTheme === ViewerCssTheme.LIGHT) {
|
342
|
+
styleSheet.deleteRule(i);
|
343
|
+
return;
|
344
|
+
}
|
345
|
+
|
346
|
+
const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
|
347
|
+
|
348
|
+
if (darkRules?.[1]) {
|
349
|
+
styleSheet.deleteRule(i);
|
350
|
+
styleSheet.insertRule(darkRules[1], i);
|
351
|
+
}
|
352
|
+
|
353
|
+
return;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
} catch (reason) {
|
357
|
+
console.error(`_forceCssTheme: "${reason?.message}".`);
|
358
|
+
}
|
359
|
+
},
|
360
|
+
|
308
361
|
async _initializeViewerComponents() {
|
309
362
|
const appConfig = this.appConfig;
|
310
363
|
const eventBus = appConfig.eventBus || new _ui_utils.EventBus({
|
@@ -347,7 +400,9 @@ const PDFViewerApplication = {
|
|
347
400
|
renderInteractiveForms: _app_options.AppOptions.get("renderInteractiveForms"),
|
348
401
|
enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
|
349
402
|
useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
|
350
|
-
maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels")
|
403
|
+
maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
|
404
|
+
enableScripting: _app_options.AppOptions.get("enableScripting"),
|
405
|
+
mouseState: this._mouseState
|
351
406
|
});
|
352
407
|
pdfRenderingQueue.setViewer(this.pdfViewer);
|
353
408
|
pdfLinkService.setViewer(this.pdfViewer);
|
@@ -478,10 +533,6 @@ const PDFViewerApplication = {
|
|
478
533
|
this.pdfViewer.currentPageNumber = val;
|
479
534
|
},
|
480
535
|
|
481
|
-
get printing() {
|
482
|
-
return !!this.printService;
|
483
|
-
},
|
484
|
-
|
485
536
|
get supportsPrinting() {
|
486
537
|
return PDFPrintServiceFactory.instance.supportsPrinting;
|
487
538
|
},
|
@@ -489,9 +540,9 @@ const PDFViewerApplication = {
|
|
489
540
|
get supportsFullscreen() {
|
490
541
|
let support;
|
491
542
|
const doc = document.documentElement;
|
492
|
-
support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen
|
543
|
+
support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen);
|
493
544
|
|
494
|
-
if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false
|
545
|
+
if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false) {
|
495
546
|
support = false;
|
496
547
|
}
|
497
548
|
|
@@ -543,6 +594,52 @@ const PDFViewerApplication = {
|
|
543
594
|
document.title = title;
|
544
595
|
},
|
545
596
|
|
597
|
+
get _docFilename() {
|
598
|
+
return this._contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
|
599
|
+
},
|
600
|
+
|
601
|
+
_cancelIdleCallbacks() {
|
602
|
+
if (!this._idleCallbacks.size) {
|
603
|
+
return;
|
604
|
+
}
|
605
|
+
|
606
|
+
for (const callback of this._idleCallbacks) {
|
607
|
+
window.cancelIdleCallback(callback);
|
608
|
+
}
|
609
|
+
|
610
|
+
this._idleCallbacks.clear();
|
611
|
+
},
|
612
|
+
|
613
|
+
async _destroyScriptingInstance() {
|
614
|
+
if (!this._scriptingInstance) {
|
615
|
+
return;
|
616
|
+
}
|
617
|
+
|
618
|
+
const {
|
619
|
+
scripting,
|
620
|
+
internalEvents,
|
621
|
+
domEvents
|
622
|
+
} = this._scriptingInstance;
|
623
|
+
|
624
|
+
try {
|
625
|
+
await scripting.destroySandbox();
|
626
|
+
} catch (ex) {}
|
627
|
+
|
628
|
+
for (const [name, listener] of internalEvents) {
|
629
|
+
this.eventBus._off(name, listener);
|
630
|
+
}
|
631
|
+
|
632
|
+
internalEvents.clear();
|
633
|
+
|
634
|
+
for (const [name, listener] of domEvents) {
|
635
|
+
window.removeEventListener(name, listener);
|
636
|
+
}
|
637
|
+
|
638
|
+
domEvents.clear();
|
639
|
+
delete this._mouseState.isDown;
|
640
|
+
this._scriptingInstance = null;
|
641
|
+
},
|
642
|
+
|
546
643
|
async close() {
|
547
644
|
const errorWrapper = this.appConfig.errorWrapper.container;
|
548
645
|
errorWrapper.setAttribute("hidden", "true");
|
@@ -551,7 +648,8 @@ const PDFViewerApplication = {
|
|
551
648
|
return undefined;
|
552
649
|
}
|
553
650
|
|
554
|
-
const
|
651
|
+
const promises = [];
|
652
|
+
promises.push(this.pdfLoadingTask.destroy());
|
555
653
|
this.pdfLoadingTask = null;
|
556
654
|
|
557
655
|
if (this.pdfDocument) {
|
@@ -568,9 +666,16 @@ const PDFViewerApplication = {
|
|
568
666
|
this.downloadComplete = false;
|
569
667
|
this.url = "";
|
570
668
|
this.baseUrl = "";
|
571
|
-
this.
|
669
|
+
this.documentInfo = null;
|
670
|
+
this.metadata = null;
|
671
|
+
this._contentDispositionFilename = null;
|
672
|
+
this._contentLength = null;
|
572
673
|
this.triggerDelayedFallback = null;
|
573
674
|
this._saveInProgress = false;
|
675
|
+
|
676
|
+
this._cancelIdleCallbacks();
|
677
|
+
|
678
|
+
promises.push(this._destroyScriptingInstance());
|
574
679
|
this.pdfSidebar.reset();
|
575
680
|
this.pdfOutlineViewer.reset();
|
576
681
|
this.pdfAttachmentViewer.reset();
|
@@ -591,7 +696,8 @@ const PDFViewerApplication = {
|
|
591
696
|
PDFBug.cleanup();
|
592
697
|
}
|
593
698
|
|
594
|
-
|
699
|
+
await Promise.all(promises);
|
700
|
+
return undefined;
|
595
701
|
},
|
596
702
|
|
597
703
|
async open(file, args) {
|
@@ -629,13 +735,7 @@ const PDFViewerApplication = {
|
|
629
735
|
|
630
736
|
if (args) {
|
631
737
|
for (const key in args) {
|
632
|
-
|
633
|
-
|
634
|
-
if (key === "length") {
|
635
|
-
this.pdfDocumentProperties.setFileSize(value);
|
636
|
-
}
|
637
|
-
|
638
|
-
parameters[key] = value;
|
738
|
+
parameters[key] = args[key];
|
639
739
|
}
|
640
740
|
}
|
641
741
|
|
@@ -663,7 +763,7 @@ const PDFViewerApplication = {
|
|
663
763
|
return undefined;
|
664
764
|
}
|
665
765
|
|
666
|
-
const message = exception
|
766
|
+
const message = exception?.message;
|
667
767
|
let loadingErrorMessage;
|
668
768
|
|
669
769
|
if (exception instanceof _pdf.InvalidPDFException) {
|
@@ -692,13 +792,9 @@ const PDFViewerApplication = {
|
|
692
792
|
downloadManager.downloadUrl(url, filename);
|
693
793
|
}
|
694
794
|
|
695
|
-
const
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
downloadManager.onerror = err => {
|
700
|
-
this.error(`PDF failed to download: ${err}`);
|
701
|
-
};
|
795
|
+
const downloadManager = this.downloadManager,
|
796
|
+
url = this.baseUrl,
|
797
|
+
filename = this._docFilename;
|
702
798
|
|
703
799
|
if (!this.pdfDocument || !this.downloadComplete) {
|
704
800
|
downloadByUrl();
|
@@ -713,20 +809,16 @@ const PDFViewerApplication = {
|
|
713
809
|
}).catch(downloadByUrl);
|
714
810
|
},
|
715
811
|
|
716
|
-
save({
|
812
|
+
async save({
|
717
813
|
sourceEventType = "download"
|
718
814
|
} = {}) {
|
719
815
|
if (this._saveInProgress) {
|
720
816
|
return;
|
721
817
|
}
|
722
818
|
|
723
|
-
const
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
downloadManager.onerror = err => {
|
728
|
-
this.error(`PDF failed to be saved: ${err}`);
|
729
|
-
};
|
819
|
+
const downloadManager = this.downloadManager,
|
820
|
+
url = this.baseUrl,
|
821
|
+
filename = this._docFilename;
|
730
822
|
|
731
823
|
if (!this.pdfDocument || !this.downloadComplete) {
|
732
824
|
this.download({
|
@@ -736,6 +828,10 @@ const PDFViewerApplication = {
|
|
736
828
|
}
|
737
829
|
|
738
830
|
this._saveInProgress = true;
|
831
|
+
await this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
832
|
+
id: "doc",
|
833
|
+
name: "WillSave"
|
834
|
+
});
|
739
835
|
this.pdfDocument.saveDocument(this.pdfDocument.annotationStorage).then(data => {
|
740
836
|
const blob = new Blob([data], {
|
741
837
|
type: "application/pdf"
|
@@ -745,11 +841,23 @@ const PDFViewerApplication = {
|
|
745
841
|
this.download({
|
746
842
|
sourceEventType
|
747
843
|
});
|
748
|
-
}).finally(() => {
|
844
|
+
}).finally(async () => {
|
845
|
+
await this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
846
|
+
id: "doc",
|
847
|
+
name: "DidSave"
|
848
|
+
});
|
749
849
|
this._saveInProgress = false;
|
750
850
|
});
|
751
851
|
},
|
752
852
|
|
853
|
+
downloadOrSave(options) {
|
854
|
+
if (this.pdfDocument?.annotationStorage.size > 0) {
|
855
|
+
this.save(options);
|
856
|
+
} else {
|
857
|
+
this.download(options);
|
858
|
+
}
|
859
|
+
},
|
860
|
+
|
753
861
|
_delayedFallback(featureId) {
|
754
862
|
this.externalServices.reportTelemetry({
|
755
863
|
type: "unsupportedFeature",
|
@@ -778,12 +886,12 @@ const PDFViewerApplication = {
|
|
778
886
|
this.externalServices.fallback({
|
779
887
|
featureId,
|
780
888
|
url: this.baseUrl
|
781
|
-
}
|
889
|
+
}).then(download => {
|
782
890
|
if (!download) {
|
783
891
|
return;
|
784
892
|
}
|
785
893
|
|
786
|
-
|
894
|
+
this.download({
|
787
895
|
sourceEventType: "download"
|
788
896
|
});
|
789
897
|
});
|
@@ -885,7 +993,10 @@ const PDFViewerApplication = {
|
|
885
993
|
|
886
994
|
load(pdfDocument) {
|
887
995
|
this.pdfDocument = pdfDocument;
|
888
|
-
pdfDocument.getDownloadInfo().then((
|
996
|
+
pdfDocument.getDownloadInfo().then(({
|
997
|
+
length
|
998
|
+
}) => {
|
999
|
+
this._contentLength = length;
|
889
1000
|
this.downloadComplete = true;
|
890
1001
|
this.loadingBar.hide();
|
891
1002
|
firstPagePromise.then(() => {
|
@@ -903,16 +1014,6 @@ const PDFViewerApplication = {
|
|
903
1014
|
baseDocumentUrl = null;
|
904
1015
|
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
905
1016
|
this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
|
906
|
-
const annotationStorage = pdfDocument.annotationStorage;
|
907
|
-
|
908
|
-
annotationStorage.onSetModified = function () {
|
909
|
-
window.addEventListener("beforeunload", beforeUnload);
|
910
|
-
};
|
911
|
-
|
912
|
-
annotationStorage.onResetModified = function () {
|
913
|
-
window.removeEventListener("beforeunload", beforeUnload);
|
914
|
-
};
|
915
|
-
|
916
1017
|
const pdfViewer = this.pdfViewer;
|
917
1018
|
pdfViewer.setDocument(pdfDocument);
|
918
1019
|
const {
|
@@ -928,7 +1029,7 @@ const PDFViewerApplication = {
|
|
928
1029
|
scrollLeft: "0",
|
929
1030
|
scrollTop: "0",
|
930
1031
|
rotation: null,
|
931
|
-
sidebarView:
|
1032
|
+
sidebarView: _ui_utils.SidebarView.UNKNOWN,
|
932
1033
|
scrollMode: _ui_utils.ScrollMode.UNKNOWN,
|
933
1034
|
spreadMode: _ui_utils.SpreadMode.UNKNOWN
|
934
1035
|
}).catch(() => {
|
@@ -936,6 +1037,9 @@ const PDFViewerApplication = {
|
|
936
1037
|
});
|
937
1038
|
firstPagePromise.then(pdfPage => {
|
938
1039
|
this.loadingBar.setWidth(this.appConfig.viewerContainer);
|
1040
|
+
|
1041
|
+
this._initializeAnnotationStorageCallbacks(pdfDocument);
|
1042
|
+
|
939
1043
|
Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
|
940
1044
|
const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
|
941
1045
|
|
@@ -962,7 +1066,7 @@ const PDFViewerApplication = {
|
|
962
1066
|
hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
|
963
1067
|
rotation = parseInt(stored.rotation, 10);
|
964
1068
|
|
965
|
-
if (sidebarView ===
|
1069
|
+
if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
|
966
1070
|
sidebarView = stored.sidebarView | 0;
|
967
1071
|
}
|
968
1072
|
|
@@ -975,7 +1079,7 @@ const PDFViewerApplication = {
|
|
975
1079
|
}
|
976
1080
|
}
|
977
1081
|
|
978
|
-
if (pageMode && sidebarView ===
|
1082
|
+
if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
|
979
1083
|
sidebarView = apiPageModeToSidebarView(pageMode);
|
980
1084
|
}
|
981
1085
|
|
@@ -1026,7 +1130,8 @@ const PDFViewerApplication = {
|
|
1026
1130
|
onePageRendered.then(() => {
|
1027
1131
|
pdfDocument.getOutline().then(outline => {
|
1028
1132
|
this.pdfOutlineViewer.render({
|
1029
|
-
outline
|
1133
|
+
outline,
|
1134
|
+
pdfDocument
|
1030
1135
|
});
|
1031
1136
|
});
|
1032
1137
|
pdfDocument.getAttachments().then(attachments => {
|
@@ -1040,6 +1145,20 @@ const PDFViewerApplication = {
|
|
1040
1145
|
pdfDocument
|
1041
1146
|
});
|
1042
1147
|
});
|
1148
|
+
|
1149
|
+
if ("requestIdleCallback" in window) {
|
1150
|
+
const callback = window.requestIdleCallback(() => {
|
1151
|
+
this._collectTelemetry(pdfDocument);
|
1152
|
+
|
1153
|
+
this._idleCallbacks.delete(callback);
|
1154
|
+
}, {
|
1155
|
+
timeout: 1000
|
1156
|
+
});
|
1157
|
+
|
1158
|
+
this._idleCallbacks.add(callback);
|
1159
|
+
}
|
1160
|
+
|
1161
|
+
this._initializeJavaScript(pdfDocument);
|
1043
1162
|
});
|
1044
1163
|
|
1045
1164
|
this._initializePageLabels(pdfDocument);
|
@@ -1047,8 +1166,261 @@ const PDFViewerApplication = {
|
|
1047
1166
|
this._initializeMetadata(pdfDocument);
|
1048
1167
|
},
|
1049
1168
|
|
1169
|
+
async _initializeJavaScript(pdfDocument) {
|
1170
|
+
if (!_app_options.AppOptions.get("enableScripting")) {
|
1171
|
+
return;
|
1172
|
+
}
|
1173
|
+
|
1174
|
+
const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
|
1175
|
+
|
1176
|
+
if (!objects && !docActions) {
|
1177
|
+
return;
|
1178
|
+
}
|
1179
|
+
|
1180
|
+
if (pdfDocument !== this.pdfDocument) {
|
1181
|
+
return;
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
const scripting = this.externalServices.createScripting({
|
1185
|
+
sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc")
|
1186
|
+
});
|
1187
|
+
const internalEvents = new Map(),
|
1188
|
+
domEvents = new Map();
|
1189
|
+
this._scriptingInstance = {
|
1190
|
+
scripting,
|
1191
|
+
ready: false,
|
1192
|
+
internalEvents,
|
1193
|
+
domEvents
|
1194
|
+
};
|
1195
|
+
|
1196
|
+
if (!this.documentInfo) {
|
1197
|
+
await new Promise(resolve => {
|
1198
|
+
this.eventBus._on("metadataloaded", evt => {
|
1199
|
+
resolve();
|
1200
|
+
}, {
|
1201
|
+
once: true
|
1202
|
+
});
|
1203
|
+
});
|
1204
|
+
|
1205
|
+
if (pdfDocument !== this.pdfDocument) {
|
1206
|
+
return;
|
1207
|
+
}
|
1208
|
+
}
|
1209
|
+
|
1210
|
+
if (!this._contentLength) {
|
1211
|
+
await new Promise(resolve => {
|
1212
|
+
this.eventBus._on("documentloaded", evt => {
|
1213
|
+
resolve();
|
1214
|
+
}, {
|
1215
|
+
once: true
|
1216
|
+
});
|
1217
|
+
});
|
1218
|
+
|
1219
|
+
if (pdfDocument !== this.pdfDocument) {
|
1220
|
+
return;
|
1221
|
+
}
|
1222
|
+
}
|
1223
|
+
|
1224
|
+
const updateFromSandbox = ({
|
1225
|
+
detail
|
1226
|
+
}) => {
|
1227
|
+
const {
|
1228
|
+
id,
|
1229
|
+
command,
|
1230
|
+
value
|
1231
|
+
} = detail;
|
1232
|
+
|
1233
|
+
if (!id) {
|
1234
|
+
switch (command) {
|
1235
|
+
case "clear":
|
1236
|
+
console.clear();
|
1237
|
+
break;
|
1238
|
+
|
1239
|
+
case "error":
|
1240
|
+
console.error(value);
|
1241
|
+
break;
|
1242
|
+
|
1243
|
+
case "layout":
|
1244
|
+
this.pdfViewer.spreadMode = apiPageLayoutToSpreadMode(value);
|
1245
|
+
break;
|
1246
|
+
|
1247
|
+
case "page-num":
|
1248
|
+
this.pdfViewer.currentPageNumber = value + 1;
|
1249
|
+
break;
|
1250
|
+
|
1251
|
+
case "print":
|
1252
|
+
this.pdfViewer.pagesPromise.then(() => {
|
1253
|
+
this.triggerPrinting();
|
1254
|
+
});
|
1255
|
+
break;
|
1256
|
+
|
1257
|
+
case "println":
|
1258
|
+
console.log(value);
|
1259
|
+
break;
|
1260
|
+
|
1261
|
+
case "zoom":
|
1262
|
+
this.pdfViewer.currentScaleValue = value;
|
1263
|
+
break;
|
1264
|
+
}
|
1265
|
+
|
1266
|
+
return;
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
const element = document.getElementById(id);
|
1270
|
+
|
1271
|
+
if (element) {
|
1272
|
+
element.dispatchEvent(new CustomEvent("updatefromsandbox", {
|
1273
|
+
detail
|
1274
|
+
}));
|
1275
|
+
} else {
|
1276
|
+
if (value !== undefined && value !== null) {
|
1277
|
+
pdfDocument.annotationStorage.setValue(id, value);
|
1278
|
+
}
|
1279
|
+
}
|
1280
|
+
};
|
1281
|
+
|
1282
|
+
internalEvents.set("updatefromsandbox", updateFromSandbox);
|
1283
|
+
const visitedPages = new Map();
|
1284
|
+
|
1285
|
+
const pageOpen = ({
|
1286
|
+
pageNumber,
|
1287
|
+
actionsPromise
|
1288
|
+
}) => {
|
1289
|
+
visitedPages.set(pageNumber, (async () => {
|
1290
|
+
let actions = null;
|
1291
|
+
|
1292
|
+
if (!visitedPages.has(pageNumber)) {
|
1293
|
+
actions = await actionsPromise;
|
1294
|
+
|
1295
|
+
if (pdfDocument !== this.pdfDocument) {
|
1296
|
+
return;
|
1297
|
+
}
|
1298
|
+
}
|
1299
|
+
|
1300
|
+
await this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
1301
|
+
id: "page",
|
1302
|
+
name: "PageOpen",
|
1303
|
+
pageNumber,
|
1304
|
+
actions
|
1305
|
+
});
|
1306
|
+
})());
|
1307
|
+
};
|
1308
|
+
|
1309
|
+
const pageClose = async ({
|
1310
|
+
pageNumber
|
1311
|
+
}) => {
|
1312
|
+
const actionsPromise = visitedPages.get(pageNumber);
|
1313
|
+
|
1314
|
+
if (!actionsPromise) {
|
1315
|
+
return;
|
1316
|
+
}
|
1317
|
+
|
1318
|
+
visitedPages.set(pageNumber, null);
|
1319
|
+
await actionsPromise;
|
1320
|
+
|
1321
|
+
if (pdfDocument !== this.pdfDocument) {
|
1322
|
+
return;
|
1323
|
+
}
|
1324
|
+
|
1325
|
+
await this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
1326
|
+
id: "page",
|
1327
|
+
name: "PageClose",
|
1328
|
+
pageNumber
|
1329
|
+
});
|
1330
|
+
};
|
1331
|
+
|
1332
|
+
internalEvents.set("pageopen", pageOpen);
|
1333
|
+
internalEvents.set("pageclose", pageClose);
|
1334
|
+
|
1335
|
+
const dispatchEventInSandbox = ({
|
1336
|
+
detail
|
1337
|
+
}) => {
|
1338
|
+
scripting.dispatchEventInSandbox(detail);
|
1339
|
+
};
|
1340
|
+
|
1341
|
+
internalEvents.set("dispatcheventinsandbox", dispatchEventInSandbox);
|
1342
|
+
|
1343
|
+
const mouseDown = event => {
|
1344
|
+
this._mouseState.isDown = true;
|
1345
|
+
};
|
1346
|
+
|
1347
|
+
domEvents.set("mousedown", mouseDown);
|
1348
|
+
|
1349
|
+
const mouseUp = event => {
|
1350
|
+
this._mouseState.isDown = false;
|
1351
|
+
};
|
1352
|
+
|
1353
|
+
domEvents.set("mouseup", mouseUp);
|
1354
|
+
|
1355
|
+
for (const [name, listener] of internalEvents) {
|
1356
|
+
this.eventBus._on(name, listener);
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
for (const [name, listener] of domEvents) {
|
1360
|
+
window.addEventListener(name, listener);
|
1361
|
+
}
|
1362
|
+
|
1363
|
+
try {
|
1364
|
+
await scripting.createSandbox({
|
1365
|
+
objects,
|
1366
|
+
calculationOrder,
|
1367
|
+
appInfo: {
|
1368
|
+
platform: navigator.platform,
|
1369
|
+
language: navigator.language
|
1370
|
+
},
|
1371
|
+
docInfo: { ...this.documentInfo,
|
1372
|
+
baseURL: this.baseUrl,
|
1373
|
+
filesize: this._contentLength,
|
1374
|
+
filename: this._docFilename,
|
1375
|
+
metadata: this.metadata?.getRaw(),
|
1376
|
+
authors: this.metadata?.get("dc:creator"),
|
1377
|
+
numPages: pdfDocument.numPages,
|
1378
|
+
URL: this.url,
|
1379
|
+
actions: docActions
|
1380
|
+
}
|
1381
|
+
});
|
1382
|
+
|
1383
|
+
if (this.externalServices.isInAutomation) {
|
1384
|
+
this.eventBus.dispatch("sandboxcreated", {
|
1385
|
+
source: this
|
1386
|
+
});
|
1387
|
+
}
|
1388
|
+
} catch (error) {
|
1389
|
+
console.error(`_initializeJavaScript: "${error?.message}".`);
|
1390
|
+
|
1391
|
+
this._destroyScriptingInstance();
|
1392
|
+
|
1393
|
+
return;
|
1394
|
+
}
|
1395
|
+
|
1396
|
+
await scripting.dispatchEventInSandbox({
|
1397
|
+
id: "doc",
|
1398
|
+
name: "Open"
|
1399
|
+
});
|
1400
|
+
await this.pdfViewer.initializeScriptingEvents();
|
1401
|
+
Promise.resolve().then(() => {
|
1402
|
+
if (this._scriptingInstance) {
|
1403
|
+
this._scriptingInstance.ready = true;
|
1404
|
+
}
|
1405
|
+
});
|
1406
|
+
},
|
1407
|
+
|
1408
|
+
async _collectTelemetry(pdfDocument) {
|
1409
|
+
const markInfo = await this.pdfDocument.getMarkInfo();
|
1410
|
+
|
1411
|
+
if (pdfDocument !== this.pdfDocument) {
|
1412
|
+
return;
|
1413
|
+
}
|
1414
|
+
|
1415
|
+
const tagged = markInfo?.Marked || false;
|
1416
|
+
this.externalServices.reportTelemetry({
|
1417
|
+
type: "tagged",
|
1418
|
+
tagged
|
1419
|
+
});
|
1420
|
+
},
|
1421
|
+
|
1050
1422
|
async _initializeAutoPrint(pdfDocument, openActionPromise) {
|
1051
|
-
const [openAction, javaScript] = await Promise.all([openActionPromise, pdfDocument.getJavaScript()]);
|
1423
|
+
const [openAction, javaScript] = await Promise.all([openActionPromise, !_app_options.AppOptions.get("enableScripting") ? pdfDocument.getJavaScript() : null]);
|
1052
1424
|
|
1053
1425
|
if (pdfDocument !== this.pdfDocument) {
|
1054
1426
|
return;
|
@@ -1056,7 +1428,7 @@ const PDFViewerApplication = {
|
|
1056
1428
|
|
1057
1429
|
let triggerAutoPrint = false;
|
1058
1430
|
|
1059
|
-
if (openAction
|
1431
|
+
if (openAction?.action === "Print") {
|
1060
1432
|
triggerAutoPrint = true;
|
1061
1433
|
}
|
1062
1434
|
|
@@ -1083,14 +1455,8 @@ const PDFViewerApplication = {
|
|
1083
1455
|
}
|
1084
1456
|
}
|
1085
1457
|
|
1086
|
-
if (!this.supportsPrinting) {
|
1087
|
-
return;
|
1088
|
-
}
|
1089
|
-
|
1090
1458
|
if (triggerAutoPrint) {
|
1091
|
-
|
1092
|
-
window.print();
|
1093
|
-
});
|
1459
|
+
this.triggerPrinting();
|
1094
1460
|
}
|
1095
1461
|
},
|
1096
1462
|
|
@@ -1098,7 +1464,8 @@ const PDFViewerApplication = {
|
|
1098
1464
|
const {
|
1099
1465
|
info,
|
1100
1466
|
metadata,
|
1101
|
-
contentDispositionFilename
|
1467
|
+
contentDispositionFilename,
|
1468
|
+
contentLength
|
1102
1469
|
} = await pdfDocument.getMetadata();
|
1103
1470
|
|
1104
1471
|
if (pdfDocument !== this.pdfDocument) {
|
@@ -1107,7 +1474,8 @@ const PDFViewerApplication = {
|
|
1107
1474
|
|
1108
1475
|
this.documentInfo = info;
|
1109
1476
|
this.metadata = metadata;
|
1110
|
-
this.
|
1477
|
+
this._contentDispositionFilename = contentDispositionFilename;
|
1478
|
+
this._contentLength ?? (this._contentLength = contentLength);
|
1111
1479
|
console.log(`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdf.version || "-"}` + `${this.pdfViewer.enableWebGL ? " [WebGL]" : ""})`);
|
1112
1480
|
let pdfTitle;
|
1113
1481
|
const infoTitle = info && info.Title;
|
@@ -1155,7 +1523,7 @@ const PDFViewerApplication = {
|
|
1155
1523
|
return false;
|
1156
1524
|
}
|
1157
1525
|
|
1158
|
-
generatorId = generator.replace(/[
|
1526
|
+
generatorId = generator.replace(/[ .-]/g, "_");
|
1159
1527
|
return true;
|
1160
1528
|
});
|
1161
1529
|
}
|
@@ -1174,6 +1542,9 @@ const PDFViewerApplication = {
|
|
1174
1542
|
generator: generatorId,
|
1175
1543
|
formType
|
1176
1544
|
});
|
1545
|
+
this.eventBus.dispatch("metadataloaded", {
|
1546
|
+
source: this
|
1547
|
+
});
|
1177
1548
|
},
|
1178
1549
|
|
1179
1550
|
async _initializePageLabels(pdfDocument) {
|
@@ -1260,6 +1631,24 @@ const PDFViewerApplication = {
|
|
1260
1631
|
}
|
1261
1632
|
},
|
1262
1633
|
|
1634
|
+
_initializeAnnotationStorageCallbacks(pdfDocument) {
|
1635
|
+
if (pdfDocument !== this.pdfDocument) {
|
1636
|
+
return;
|
1637
|
+
}
|
1638
|
+
|
1639
|
+
const {
|
1640
|
+
annotationStorage
|
1641
|
+
} = pdfDocument;
|
1642
|
+
|
1643
|
+
annotationStorage.onSetModified = function () {
|
1644
|
+
window.addEventListener("beforeunload", beforeUnload);
|
1645
|
+
};
|
1646
|
+
|
1647
|
+
annotationStorage.onResetModified = function () {
|
1648
|
+
window.removeEventListener("beforeunload", beforeUnload);
|
1649
|
+
};
|
1650
|
+
},
|
1651
|
+
|
1263
1652
|
setInitialView(storedHash, {
|
1264
1653
|
rotation,
|
1265
1654
|
sidebarView,
|
@@ -1318,12 +1707,17 @@ const PDFViewerApplication = {
|
|
1318
1707
|
},
|
1319
1708
|
|
1320
1709
|
forceRendering() {
|
1321
|
-
this.pdfRenderingQueue.printing = this.
|
1710
|
+
this.pdfRenderingQueue.printing = !!this.printService;
|
1322
1711
|
this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
|
1323
1712
|
this.pdfRenderingQueue.renderHighestPriority();
|
1324
1713
|
},
|
1325
1714
|
|
1326
1715
|
beforePrint() {
|
1716
|
+
this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
1717
|
+
id: "doc",
|
1718
|
+
name: "WillPrint"
|
1719
|
+
});
|
1720
|
+
|
1327
1721
|
if (this.printService) {
|
1328
1722
|
return;
|
1329
1723
|
}
|
@@ -1358,6 +1752,11 @@ const PDFViewerApplication = {
|
|
1358
1752
|
},
|
1359
1753
|
|
1360
1754
|
afterPrint() {
|
1755
|
+
this._scriptingInstance?.scripting.dispatchEventInSandbox({
|
1756
|
+
id: "doc",
|
1757
|
+
name: "DidPrint"
|
1758
|
+
});
|
1759
|
+
|
1361
1760
|
if (this.printService) {
|
1362
1761
|
this.printService.destroy();
|
1363
1762
|
this.printService = null;
|
@@ -1387,6 +1786,14 @@ const PDFViewerApplication = {
|
|
1387
1786
|
this.pdfPresentationMode.request();
|
1388
1787
|
},
|
1389
1788
|
|
1789
|
+
triggerPrinting() {
|
1790
|
+
if (!this.supportsPrinting) {
|
1791
|
+
return;
|
1792
|
+
}
|
1793
|
+
|
1794
|
+
window.print();
|
1795
|
+
},
|
1796
|
+
|
1390
1797
|
bindEvents() {
|
1391
1798
|
const {
|
1392
1799
|
eventBus,
|
@@ -1471,6 +1878,14 @@ const PDFViewerApplication = {
|
|
1471
1878
|
|
1472
1879
|
eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
|
1473
1880
|
|
1881
|
+
if (_app_options.AppOptions.get("pdfBug")) {
|
1882
|
+
_boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
|
1883
|
+
|
1884
|
+
eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
|
1885
|
+
|
1886
|
+
eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
|
1887
|
+
}
|
1888
|
+
|
1474
1889
|
eventBus._on("fileinputchange", webViewerFileInputChange);
|
1475
1890
|
|
1476
1891
|
eventBus._on("openfile", webViewerOpenFile);
|
@@ -1507,6 +1922,13 @@ const PDFViewerApplication = {
|
|
1507
1922
|
});
|
1508
1923
|
};
|
1509
1924
|
|
1925
|
+
_boundEvents.windowUpdateFromSandbox = event => {
|
1926
|
+
eventBus.dispatch("updatefromsandbox", {
|
1927
|
+
source: window,
|
1928
|
+
detail: event.detail
|
1929
|
+
});
|
1930
|
+
};
|
1931
|
+
|
1510
1932
|
window.addEventListener("visibilitychange", webViewerVisibilityChange);
|
1511
1933
|
window.addEventListener("wheel", webViewerWheel, {
|
1512
1934
|
passive: false
|
@@ -1521,6 +1943,7 @@ const PDFViewerApplication = {
|
|
1521
1943
|
window.addEventListener("hashchange", _boundEvents.windowHashChange);
|
1522
1944
|
window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
1523
1945
|
window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
|
1946
|
+
window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
|
1524
1947
|
},
|
1525
1948
|
|
1526
1949
|
unbindEvents() {
|
@@ -1605,6 +2028,14 @@ const PDFViewerApplication = {
|
|
1605
2028
|
|
1606
2029
|
eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
|
1607
2030
|
|
2031
|
+
if (_boundEvents.reportPageStatsPDFBug) {
|
2032
|
+
eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
|
2033
|
+
|
2034
|
+
eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
|
2035
|
+
|
2036
|
+
_boundEvents.reportPageStatsPDFBug = null;
|
2037
|
+
}
|
2038
|
+
|
1608
2039
|
eventBus._off("fileinputchange", webViewerFileInputChange);
|
1609
2040
|
|
1610
2041
|
eventBus._off("openfile", webViewerOpenFile);
|
@@ -1631,10 +2062,12 @@ const PDFViewerApplication = {
|
|
1631
2062
|
window.removeEventListener("hashchange", _boundEvents.windowHashChange);
|
1632
2063
|
window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
1633
2064
|
window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
|
2065
|
+
window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
|
1634
2066
|
_boundEvents.windowResize = null;
|
1635
2067
|
_boundEvents.windowHashChange = null;
|
1636
2068
|
_boundEvents.windowBeforePrint = null;
|
1637
2069
|
_boundEvents.windowAfterPrint = null;
|
2070
|
+
_boundEvents.windowUpdateFromSandbox = null;
|
1638
2071
|
},
|
1639
2072
|
|
1640
2073
|
accumulateWheelTicks(ticks) {
|
@@ -1646,6 +2079,10 @@ const PDFViewerApplication = {
|
|
1646
2079
|
const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
|
1647
2080
|
this._wheelUnusedTicks -= wholeTicks;
|
1648
2081
|
return wholeTicks;
|
2082
|
+
},
|
2083
|
+
|
2084
|
+
get scriptingReady() {
|
2085
|
+
return this._scriptingInstance?.ready || false;
|
1649
2086
|
}
|
1650
2087
|
|
1651
2088
|
};
|
@@ -1704,6 +2141,23 @@ function loadAndEnablePDFBug(enabledTabs) {
|
|
1704
2141
|
});
|
1705
2142
|
}
|
1706
2143
|
|
2144
|
+
function reportPageStatsPDFBug({
|
2145
|
+
pageNumber
|
2146
|
+
}) {
|
2147
|
+
if (typeof Stats === "undefined" || !Stats.enabled) {
|
2148
|
+
return;
|
2149
|
+
}
|
2150
|
+
|
2151
|
+
const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
|
2152
|
+
const pageStats = pageView && pageView.pdfPage && pageView.pdfPage.stats;
|
2153
|
+
|
2154
|
+
if (!pageStats) {
|
2155
|
+
return;
|
2156
|
+
}
|
2157
|
+
|
2158
|
+
Stats.add(pageNumber, pageStats);
|
2159
|
+
}
|
2160
|
+
|
1707
2161
|
function webViewerInitialized() {
|
1708
2162
|
const appConfig = PDFViewerApplication.appConfig;
|
1709
2163
|
let file;
|
@@ -1829,37 +2283,33 @@ function webViewerResetPermissions() {
|
|
1829
2283
|
appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
|
1830
2284
|
}
|
1831
2285
|
|
1832
|
-
function webViewerPageRendered(
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
2286
|
+
function webViewerPageRendered({
|
2287
|
+
pageNumber,
|
2288
|
+
timestamp,
|
2289
|
+
error
|
2290
|
+
}) {
|
1837
2291
|
if (pageNumber === PDFViewerApplication.page) {
|
1838
2292
|
PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
|
1839
2293
|
}
|
1840
2294
|
|
1841
|
-
if (!pageView) {
|
1842
|
-
return;
|
1843
|
-
}
|
1844
|
-
|
1845
2295
|
if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
1846
|
-
const
|
1847
|
-
thumbnailView.
|
1848
|
-
}
|
2296
|
+
const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
|
2297
|
+
const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
|
1849
2298
|
|
1850
|
-
|
1851
|
-
|
2299
|
+
if (pageView && thumbnailView) {
|
2300
|
+
thumbnailView.setImage(pageView);
|
2301
|
+
}
|
1852
2302
|
}
|
1853
2303
|
|
1854
|
-
if (
|
2304
|
+
if (error) {
|
1855
2305
|
PDFViewerApplication.l10n.get("rendering_error", null, "An error occurred while rendering the page.").then(msg => {
|
1856
|
-
PDFViewerApplication.error(msg,
|
2306
|
+
PDFViewerApplication.error(msg, error);
|
1857
2307
|
});
|
1858
2308
|
}
|
1859
2309
|
|
1860
2310
|
PDFViewerApplication.externalServices.reportTelemetry({
|
1861
2311
|
type: "pageInfo",
|
1862
|
-
timestamp
|
2312
|
+
timestamp
|
1863
2313
|
});
|
1864
2314
|
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
1865
2315
|
PDFViewerApplication.externalServices.reportTelemetry({
|
@@ -1876,24 +2326,24 @@ function webViewerPageMode({
|
|
1876
2326
|
|
1877
2327
|
switch (mode) {
|
1878
2328
|
case "thumbs":
|
1879
|
-
view =
|
2329
|
+
view = _ui_utils.SidebarView.THUMBS;
|
1880
2330
|
break;
|
1881
2331
|
|
1882
2332
|
case "bookmarks":
|
1883
2333
|
case "outline":
|
1884
|
-
view =
|
2334
|
+
view = _ui_utils.SidebarView.OUTLINE;
|
1885
2335
|
break;
|
1886
2336
|
|
1887
2337
|
case "attachments":
|
1888
|
-
view =
|
2338
|
+
view = _ui_utils.SidebarView.ATTACHMENTS;
|
1889
2339
|
break;
|
1890
2340
|
|
1891
2341
|
case "layers":
|
1892
|
-
view =
|
2342
|
+
view = _ui_utils.SidebarView.LAYERS;
|
1893
2343
|
break;
|
1894
2344
|
|
1895
2345
|
case "none":
|
1896
|
-
view =
|
2346
|
+
view = _ui_utils.SidebarView.NONE;
|
1897
2347
|
break;
|
1898
2348
|
|
1899
2349
|
default:
|
@@ -1918,10 +2368,7 @@ function webViewerNamedAction(evt) {
|
|
1918
2368
|
break;
|
1919
2369
|
|
1920
2370
|
case "Print":
|
1921
|
-
|
1922
|
-
webViewerPrint();
|
1923
|
-
}
|
1924
|
-
|
2371
|
+
PDFViewerApplication.triggerPrinting();
|
1925
2372
|
break;
|
1926
2373
|
|
1927
2374
|
case "SaveAs":
|
@@ -1930,19 +2377,8 @@ function webViewerNamedAction(evt) {
|
|
1930
2377
|
}
|
1931
2378
|
}
|
1932
2379
|
|
1933
|
-
function webViewerPresentationModeChanged({
|
1934
|
-
|
1935
|
-
switchInProgress
|
1936
|
-
}) {
|
1937
|
-
let state = _ui_utils.PresentationModeState.NORMAL;
|
1938
|
-
|
1939
|
-
if (switchInProgress) {
|
1940
|
-
state = _ui_utils.PresentationModeState.CHANGING;
|
1941
|
-
} else if (active) {
|
1942
|
-
state = _ui_utils.PresentationModeState.FULLSCREEN;
|
1943
|
-
}
|
1944
|
-
|
1945
|
-
PDFViewerApplication.pdfViewer.presentationModeState = state;
|
2380
|
+
function webViewerPresentationModeChanged(evt) {
|
2381
|
+
PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
|
1946
2382
|
}
|
1947
2383
|
|
1948
2384
|
function webViewerSidebarViewChanged(evt) {
|
@@ -1972,7 +2408,7 @@ function webViewerUpdateViewarea(evt) {
|
|
1972
2408
|
PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
|
1973
2409
|
PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
|
1974
2410
|
const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
|
1975
|
-
const loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
|
2411
|
+
const loading = (currentPage && currentPage.renderingState) !== _pdf_rendering_queue.RenderingStates.FINISHED;
|
1976
2412
|
PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
|
1977
2413
|
}
|
1978
2414
|
|
@@ -2075,27 +2511,19 @@ function webViewerPresentationMode() {
|
|
2075
2511
|
}
|
2076
2512
|
|
2077
2513
|
function webViewerPrint() {
|
2078
|
-
|
2079
|
-
}
|
2080
|
-
|
2081
|
-
function webViewerDownloadOrSave(sourceEventType) {
|
2082
|
-
if (PDFViewerApplication.pdfDocument && PDFViewerApplication.pdfDocument.annotationStorage.size > 0) {
|
2083
|
-
PDFViewerApplication.save({
|
2084
|
-
sourceEventType
|
2085
|
-
});
|
2086
|
-
} else {
|
2087
|
-
PDFViewerApplication.download({
|
2088
|
-
sourceEventType
|
2089
|
-
});
|
2090
|
-
}
|
2514
|
+
PDFViewerApplication.triggerPrinting();
|
2091
2515
|
}
|
2092
2516
|
|
2093
2517
|
function webViewerDownload() {
|
2094
|
-
|
2518
|
+
PDFViewerApplication.downloadOrSave({
|
2519
|
+
sourceEventType: "download"
|
2520
|
+
});
|
2095
2521
|
}
|
2096
2522
|
|
2097
2523
|
function webViewerSave() {
|
2098
|
-
|
2524
|
+
PDFViewerApplication.downloadOrSave({
|
2525
|
+
sourceEventType: "save"
|
2526
|
+
});
|
2099
2527
|
}
|
2100
2528
|
|
2101
2529
|
function webViewerFirstPage() {
|
@@ -2111,11 +2539,11 @@ function webViewerLastPage() {
|
|
2111
2539
|
}
|
2112
2540
|
|
2113
2541
|
function webViewerNextPage() {
|
2114
|
-
PDFViewerApplication.
|
2542
|
+
PDFViewerApplication.pdfViewer.nextPage();
|
2115
2543
|
}
|
2116
2544
|
|
2117
2545
|
function webViewerPreviousPage() {
|
2118
|
-
PDFViewerApplication.
|
2546
|
+
PDFViewerApplication.pdfViewer.previousPage();
|
2119
2547
|
}
|
2120
2548
|
|
2121
2549
|
function webViewerZoomIn() {
|
@@ -2134,7 +2562,7 @@ function webViewerPageNumberChanged(evt) {
|
|
2134
2562
|
const pdfViewer = PDFViewerApplication.pdfViewer;
|
2135
2563
|
|
2136
2564
|
if (evt.value !== "") {
|
2137
|
-
|
2565
|
+
PDFViewerApplication.pdfLinkService.goToPage(evt.value);
|
2138
2566
|
}
|
2139
2567
|
|
2140
2568
|
if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
|
@@ -2231,21 +2659,15 @@ function webViewerRotationChanging(evt) {
|
|
2231
2659
|
PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
|
2232
2660
|
}
|
2233
2661
|
|
2234
|
-
function webViewerPageChanging(
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2662
|
+
function webViewerPageChanging({
|
2663
|
+
pageNumber,
|
2664
|
+
pageLabel
|
2665
|
+
}) {
|
2666
|
+
PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
|
2667
|
+
PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
|
2238
2668
|
|
2239
2669
|
if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
2240
|
-
PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(
|
2241
|
-
}
|
2242
|
-
|
2243
|
-
if (typeof Stats !== "undefined" && Stats.enabled) {
|
2244
|
-
const pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
|
2245
|
-
|
2246
|
-
if (pageView && pageView.stats) {
|
2247
|
-
Stats.add(page, pageView.stats);
|
2248
|
-
}
|
2670
|
+
PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
|
2249
2671
|
}
|
2250
2672
|
}
|
2251
2673
|
|
@@ -2364,7 +2786,7 @@ function webViewerKeyDown(evt) {
|
|
2364
2786
|
if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
|
2365
2787
|
switch (evt.keyCode) {
|
2366
2788
|
case 70:
|
2367
|
-
if (!PDFViewerApplication.supportsIntegratedFind) {
|
2789
|
+
if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
|
2368
2790
|
PDFViewerApplication.findBar.open();
|
2369
2791
|
handled = true;
|
2370
2792
|
}
|
@@ -2490,7 +2912,7 @@ function webViewerKeyDown(evt) {
|
|
2490
2912
|
return;
|
2491
2913
|
}
|
2492
2914
|
|
2493
|
-
const curElement =
|
2915
|
+
const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
|
2494
2916
|
const curElementTagName = curElement && curElement.tagName.toUpperCase();
|
2495
2917
|
|
2496
2918
|
if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement && curElement.isContentEditable) {
|
@@ -2609,13 +3031,9 @@ function webViewerKeyDown(evt) {
|
|
2609
3031
|
|
2610
3032
|
if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
|
2611
3033
|
if (turnPage > 0) {
|
2612
|
-
|
2613
|
-
PDFViewerApplication.page++;
|
2614
|
-
}
|
3034
|
+
pdfViewer.nextPage();
|
2615
3035
|
} else {
|
2616
|
-
|
2617
|
-
PDFViewerApplication.page--;
|
2618
|
-
}
|
3036
|
+
pdfViewer.previousPage();
|
2619
3037
|
}
|
2620
3038
|
|
2621
3039
|
handled = true;
|
@@ -2685,22 +3103,22 @@ function apiPageLayoutToSpreadMode(layout) {
|
|
2685
3103
|
function apiPageModeToSidebarView(mode) {
|
2686
3104
|
switch (mode) {
|
2687
3105
|
case "UseNone":
|
2688
|
-
return
|
3106
|
+
return _ui_utils.SidebarView.NONE;
|
2689
3107
|
|
2690
3108
|
case "UseThumbs":
|
2691
|
-
return
|
3109
|
+
return _ui_utils.SidebarView.THUMBS;
|
2692
3110
|
|
2693
3111
|
case "UseOutlines":
|
2694
|
-
return
|
3112
|
+
return _ui_utils.SidebarView.OUTLINE;
|
2695
3113
|
|
2696
3114
|
case "UseAttachments":
|
2697
|
-
return
|
3115
|
+
return _ui_utils.SidebarView.ATTACHMENTS;
|
2698
3116
|
|
2699
3117
|
case "UseOC":
|
2700
|
-
return
|
3118
|
+
return _ui_utils.SidebarView.LAYERS;
|
2701
3119
|
}
|
2702
3120
|
|
2703
|
-
return
|
3121
|
+
return _ui_utils.SidebarView.NONE;
|
2704
3122
|
}
|
2705
3123
|
|
2706
3124
|
const PDFPrintServiceFactory = {
|