1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = void 0;
|
28 |
|
29 | var _ui_utils = require("./ui_utils.js");
|
30 |
|
31 | var _app_options = require("./app_options.js");
|
32 |
|
33 | var _pdf = require("../pdf");
|
34 |
|
35 | var _pdf_cursor_tools = require("./pdf_cursor_tools.js");
|
36 |
|
37 | var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
|
38 |
|
39 | var _pdf_sidebar = require("./pdf_sidebar.js");
|
40 |
|
41 | var _overlay_manager = require("./overlay_manager.js");
|
42 |
|
43 | var _password_prompt = require("./password_prompt.js");
|
44 |
|
45 | var _pdf_attachment_viewer = require("./pdf_attachment_viewer.js");
|
46 |
|
47 | var _pdf_document_properties = require("./pdf_document_properties.js");
|
48 |
|
49 | var _pdf_find_bar = require("./pdf_find_bar.js");
|
50 |
|
51 | var _pdf_find_controller = require("./pdf_find_controller.js");
|
52 |
|
53 | var _pdf_history = require("./pdf_history.js");
|
54 |
|
55 | var _pdf_link_service = require("./pdf_link_service.js");
|
56 |
|
57 | var _pdf_outline_viewer = require("./pdf_outline_viewer.js");
|
58 |
|
59 | var _pdf_presentation_mode = require("./pdf_presentation_mode.js");
|
60 |
|
61 | var _pdf_sidebar_resizer = require("./pdf_sidebar_resizer.js");
|
62 |
|
63 | var _pdf_thumbnail_viewer = require("./pdf_thumbnail_viewer.js");
|
64 |
|
65 | var _pdf_viewer = require("./pdf_viewer.js");
|
66 |
|
67 | var _secondary_toolbar = require("./secondary_toolbar.js");
|
68 |
|
69 | var _toolbar = require("./toolbar.js");
|
70 |
|
71 | var _view_history = require("./view_history.js");
|
72 |
|
73 | const DEFAULT_SCALE_DELTA = 1.1;
|
74 | const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
|
75 | const FORCE_PAGES_LOADED_TIMEOUT = 10000;
|
76 | const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
|
77 | const ViewOnLoad = {
|
78 | UNKNOWN: -1,
|
79 | PREVIOUS: 0,
|
80 | INITIAL: 1
|
81 | };
|
82 |
|
83 | class DefaultExternalServices {
|
84 | constructor() {
|
85 | throw new Error("Cannot initialize DefaultExternalServices.");
|
86 | }
|
87 |
|
88 | static updateFindControlState(data) {}
|
89 |
|
90 | static updateFindMatchesCount(data) {}
|
91 |
|
92 | static initPassiveLoading(callbacks) {}
|
93 |
|
94 | static fallback(data, callback) {}
|
95 |
|
96 | static reportTelemetry(data) {}
|
97 |
|
98 | static createDownloadManager(options) {
|
99 | throw new Error("Not implemented: createDownloadManager");
|
100 | }
|
101 |
|
102 | static createPreferences() {
|
103 | throw new Error("Not implemented: createPreferences");
|
104 | }
|
105 |
|
106 | static createL10n(options) {
|
107 | throw new Error("Not implemented: createL10n");
|
108 | }
|
109 |
|
110 | static get supportsIntegratedFind() {
|
111 | return (0, _pdf.shadow)(this, "supportsIntegratedFind", false);
|
112 | }
|
113 |
|
114 | static get supportsDocumentFonts() {
|
115 | return (0, _pdf.shadow)(this, "supportsDocumentFonts", true);
|
116 | }
|
117 |
|
118 | static get supportedMouseWheelZoomModifierKeys() {
|
119 | return (0, _pdf.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
|
120 | ctrlKey: true,
|
121 | metaKey: true
|
122 | });
|
123 | }
|
124 |
|
125 | }
|
126 |
|
127 | exports.DefaultExternalServices = DefaultExternalServices;
|
128 | const PDFViewerApplication = {
|
129 | initialBookmark: document.location.hash.substring(1),
|
130 | _initializedCapability: (0, _pdf.createPromiseCapability)(),
|
131 | fellback: false,
|
132 | appConfig: null,
|
133 | pdfDocument: null,
|
134 | pdfLoadingTask: null,
|
135 | printService: null,
|
136 | pdfViewer: null,
|
137 | pdfThumbnailViewer: null,
|
138 | pdfRenderingQueue: null,
|
139 | pdfPresentationMode: null,
|
140 | pdfDocumentProperties: null,
|
141 | pdfLinkService: null,
|
142 | pdfHistory: null,
|
143 | pdfSidebar: null,
|
144 | pdfSidebarResizer: null,
|
145 | pdfOutlineViewer: null,
|
146 | pdfAttachmentViewer: null,
|
147 | pdfCursorTools: null,
|
148 | store: null,
|
149 | downloadManager: null,
|
150 | overlayManager: null,
|
151 | preferences: null,
|
152 | toolbar: null,
|
153 | secondaryToolbar: null,
|
154 | eventBus: null,
|
155 | l10n: null,
|
156 | isInitialViewSet: false,
|
157 | downloadComplete: false,
|
158 | isViewerEmbedded: window.parent !== window,
|
159 | url: "",
|
160 | baseUrl: "",
|
161 | externalServices: DefaultExternalServices,
|
162 | _boundEvents: {},
|
163 | contentDispositionFilename: null,
|
164 |
|
165 | async initialize(appConfig) {
|
166 | this.preferences = this.externalServices.createPreferences();
|
167 | this.appConfig = appConfig;
|
168 | await this._readPreferences();
|
169 | await this._parseHashParameters();
|
170 | await this._initializeL10n();
|
171 |
|
172 | if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf.LinkTarget.NONE) {
|
173 | _app_options.AppOptions.set("externalLinkTarget", _pdf.LinkTarget.TOP);
|
174 | }
|
175 |
|
176 | await this._initializeViewerComponents();
|
177 | this.bindEvents();
|
178 | this.bindWindowEvents();
|
179 | const appContainer = appConfig.appContainer || document.documentElement;
|
180 | this.l10n.translate(appContainer).then(() => {
|
181 | this.eventBus.dispatch("localized", {
|
182 | source: this
|
183 | });
|
184 | });
|
185 |
|
186 | this._initializedCapability.resolve();
|
187 | },
|
188 |
|
189 | async _readPreferences() {
|
190 | if (_app_options.AppOptions.get("disablePreferences") === true) {
|
191 | return;
|
192 | }
|
193 |
|
194 | try {
|
195 | const prefs = await this.preferences.getAll();
|
196 |
|
197 | for (const name in prefs) {
|
198 | _app_options.AppOptions.set(name, prefs[name]);
|
199 | }
|
200 | } catch (reason) {
|
201 | console.error(`_readPreferences: "${reason.message}".`);
|
202 | }
|
203 | },
|
204 |
|
205 | async _parseHashParameters() {
|
206 | if (!_app_options.AppOptions.get("pdfBugEnabled")) {
|
207 | return undefined;
|
208 | }
|
209 |
|
210 | const hash = document.location.hash.substring(1);
|
211 |
|
212 | if (!hash) {
|
213 | return undefined;
|
214 | }
|
215 |
|
216 | const hashParams = (0, _ui_utils.parseQueryString)(hash),
|
217 | waitOn = [];
|
218 |
|
219 | if ("disableworker" in hashParams && hashParams["disableworker"] === "true") {
|
220 | waitOn.push(loadFakeWorker());
|
221 | }
|
222 |
|
223 | if ("disablerange" in hashParams) {
|
224 | _app_options.AppOptions.set("disableRange", hashParams["disablerange"] === "true");
|
225 | }
|
226 |
|
227 | if ("disablestream" in hashParams) {
|
228 | _app_options.AppOptions.set("disableStream", hashParams["disablestream"] === "true");
|
229 | }
|
230 |
|
231 | if ("disableautofetch" in hashParams) {
|
232 | _app_options.AppOptions.set("disableAutoFetch", hashParams["disableautofetch"] === "true");
|
233 | }
|
234 |
|
235 | if ("disablefontface" in hashParams) {
|
236 | _app_options.AppOptions.set("disableFontFace", hashParams["disablefontface"] === "true");
|
237 | }
|
238 |
|
239 | if ("disablehistory" in hashParams) {
|
240 | _app_options.AppOptions.set("disableHistory", hashParams["disablehistory"] === "true");
|
241 | }
|
242 |
|
243 | if ("webgl" in hashParams) {
|
244 | _app_options.AppOptions.set("enableWebGL", hashParams["webgl"] === "true");
|
245 | }
|
246 |
|
247 | if ("verbosity" in hashParams) {
|
248 | _app_options.AppOptions.set("verbosity", hashParams["verbosity"] | 0);
|
249 | }
|
250 |
|
251 | if ("textlayer" in hashParams) {
|
252 | switch (hashParams["textlayer"]) {
|
253 | case "off":
|
254 | _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
|
255 |
|
256 | break;
|
257 |
|
258 | case "visible":
|
259 | case "shadow":
|
260 | case "hover":
|
261 | const viewer = this.appConfig.viewerContainer;
|
262 | viewer.classList.add("textLayer-" + hashParams["textlayer"]);
|
263 | break;
|
264 | }
|
265 | }
|
266 |
|
267 | if ("pdfbug" in hashParams) {
|
268 | _app_options.AppOptions.set("pdfBug", true);
|
269 |
|
270 | const enabled = hashParams["pdfbug"].split(",");
|
271 | waitOn.push(loadAndEnablePDFBug(enabled));
|
272 | }
|
273 |
|
274 | if ("locale" in hashParams) {
|
275 | _app_options.AppOptions.set("locale", hashParams["locale"]);
|
276 | }
|
277 |
|
278 | return Promise.all(waitOn).catch(reason => {
|
279 | console.error(`_parseHashParameters: "${reason.message}".`);
|
280 | });
|
281 | },
|
282 |
|
283 | async _initializeL10n() {
|
284 | this.l10n = this.externalServices.createL10n({
|
285 | locale: _app_options.AppOptions.get("locale")
|
286 | });
|
287 | const dir = await this.l10n.getDirection();
|
288 | document.getElementsByTagName("html")[0].dir = dir;
|
289 | },
|
290 |
|
291 | async _initializeViewerComponents() {
|
292 | const appConfig = this.appConfig;
|
293 | this.overlayManager = new _overlay_manager.OverlayManager();
|
294 | const eventBus = appConfig.eventBus || new _ui_utils.EventBus({
|
295 | dispatchToDOM: _app_options.AppOptions.get("eventBusDispatchToDOM")
|
296 | });
|
297 | this.eventBus = eventBus;
|
298 | const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
|
299 | pdfRenderingQueue.onIdle = this.cleanup.bind(this);
|
300 | this.pdfRenderingQueue = pdfRenderingQueue;
|
301 | const pdfLinkService = new _pdf_link_service.PDFLinkService({
|
302 | eventBus,
|
303 | externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
|
304 | externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
|
305 | ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
|
306 | });
|
307 | this.pdfLinkService = pdfLinkService;
|
308 | const downloadManager = this.externalServices.createDownloadManager({
|
309 | disableCreateObjectURL: _app_options.AppOptions.get("disableCreateObjectURL")
|
310 | });
|
311 | this.downloadManager = downloadManager;
|
312 | const findController = new _pdf_find_controller.PDFFindController({
|
313 | linkService: pdfLinkService,
|
314 | eventBus
|
315 | });
|
316 | this.findController = findController;
|
317 | const container = appConfig.mainContainer;
|
318 | const viewer = appConfig.viewerContainer;
|
319 | this.pdfViewer = new _pdf_viewer.PDFViewer({
|
320 | container,
|
321 | viewer,
|
322 | eventBus,
|
323 | renderingQueue: pdfRenderingQueue,
|
324 | linkService: pdfLinkService,
|
325 | downloadManager,
|
326 | findController,
|
327 | renderer: _app_options.AppOptions.get("renderer"),
|
328 | enableWebGL: _app_options.AppOptions.get("enableWebGL"),
|
329 | l10n: this.l10n,
|
330 | textLayerMode: _app_options.AppOptions.get("textLayerMode"),
|
331 | imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
|
332 | renderInteractiveForms: _app_options.AppOptions.get("renderInteractiveForms"),
|
333 | enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
|
334 | useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
|
335 | maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels")
|
336 | });
|
337 | pdfRenderingQueue.setViewer(this.pdfViewer);
|
338 | pdfLinkService.setViewer(this.pdfViewer);
|
339 | this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
|
340 | container: appConfig.sidebar.thumbnailView,
|
341 | renderingQueue: pdfRenderingQueue,
|
342 | linkService: pdfLinkService,
|
343 | l10n: this.l10n
|
344 | });
|
345 | pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
|
346 | this.pdfHistory = new _pdf_history.PDFHistory({
|
347 | linkService: pdfLinkService,
|
348 | eventBus
|
349 | });
|
350 | pdfLinkService.setHistory(this.pdfHistory);
|
351 |
|
352 | if (!this.supportsIntegratedFind) {
|
353 | this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
|
354 | }
|
355 |
|
356 | this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
|
357 | this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
|
358 | container,
|
359 | eventBus,
|
360 | cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
|
361 | });
|
362 | this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
|
363 | this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
|
364 |
|
365 | if (this.supportsFullscreen) {
|
366 | this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
|
367 | container,
|
368 | pdfViewer: this.pdfViewer,
|
369 | eventBus,
|
370 | contextMenuItems: appConfig.fullscreen
|
371 | });
|
372 | }
|
373 |
|
374 | this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n);
|
375 | this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
|
376 | container: appConfig.sidebar.outlineView,
|
377 | eventBus,
|
378 | linkService: pdfLinkService
|
379 | });
|
380 | this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
|
381 | container: appConfig.sidebar.attachmentsView,
|
382 | eventBus,
|
383 | downloadManager
|
384 | });
|
385 | this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
|
386 | elements: appConfig.sidebar,
|
387 | pdfViewer: this.pdfViewer,
|
388 | pdfThumbnailViewer: this.pdfThumbnailViewer,
|
389 | eventBus,
|
390 | l10n: this.l10n
|
391 | });
|
392 | this.pdfSidebar.onToggled = this.forceRendering.bind(this);
|
393 | this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
|
394 | },
|
395 |
|
396 | run(config) {
|
397 | this.initialize(config).then(webViewerInitialized);
|
398 | },
|
399 |
|
400 | get initialized() {
|
401 | return this._initializedCapability.settled;
|
402 | },
|
403 |
|
404 | get initializedPromise() {
|
405 | return this._initializedCapability.promise;
|
406 | },
|
407 |
|
408 | zoomIn(ticks) {
|
409 | if (this.pdfViewer.isInPresentationMode) {
|
410 | return;
|
411 | }
|
412 |
|
413 | let newScale = this.pdfViewer.currentScale;
|
414 |
|
415 | do {
|
416 | newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
|
417 | newScale = Math.ceil(newScale * 10) / 10;
|
418 | newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
|
419 | } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
|
420 |
|
421 | this.pdfViewer.currentScaleValue = newScale;
|
422 | },
|
423 |
|
424 | zoomOut(ticks) {
|
425 | if (this.pdfViewer.isInPresentationMode) {
|
426 | return;
|
427 | }
|
428 |
|
429 | let newScale = this.pdfViewer.currentScale;
|
430 |
|
431 | do {
|
432 | newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
|
433 | newScale = Math.floor(newScale * 10) / 10;
|
434 | newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
|
435 | } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
|
436 |
|
437 | this.pdfViewer.currentScaleValue = newScale;
|
438 | },
|
439 |
|
440 | zoomReset() {
|
441 | if (this.pdfViewer.isInPresentationMode) {
|
442 | return;
|
443 | }
|
444 |
|
445 | this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
|
446 | },
|
447 |
|
448 | get pagesCount() {
|
449 | return this.pdfDocument ? this.pdfDocument.numPages : 0;
|
450 | },
|
451 |
|
452 | set page(val) {
|
453 | this.pdfViewer.currentPageNumber = val;
|
454 | },
|
455 |
|
456 | get page() {
|
457 | return this.pdfViewer.currentPageNumber;
|
458 | },
|
459 |
|
460 | get printing() {
|
461 | return !!this.printService;
|
462 | },
|
463 |
|
464 | get supportsPrinting() {
|
465 | return PDFPrintServiceFactory.instance.supportsPrinting;
|
466 | },
|
467 |
|
468 | get supportsFullscreen() {
|
469 | let support;
|
470 | const doc = document.documentElement;
|
471 | support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
|
472 |
|
473 | if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
|
474 | support = false;
|
475 | }
|
476 |
|
477 | return (0, _pdf.shadow)(this, "supportsFullscreen", support);
|
478 | },
|
479 |
|
480 | get supportsIntegratedFind() {
|
481 | return this.externalServices.supportsIntegratedFind;
|
482 | },
|
483 |
|
484 | get supportsDocumentFonts() {
|
485 | return this.externalServices.supportsDocumentFonts;
|
486 | },
|
487 |
|
488 | get loadingBar() {
|
489 | const bar = new _ui_utils.ProgressBar("#loadingBar");
|
490 | return (0, _pdf.shadow)(this, "loadingBar", bar);
|
491 | },
|
492 |
|
493 | get supportedMouseWheelZoomModifierKeys() {
|
494 | return this.externalServices.supportedMouseWheelZoomModifierKeys;
|
495 | },
|
496 |
|
497 | initPassiveLoading() {
|
498 | throw new Error("Not implemented: initPassiveLoading");
|
499 | },
|
500 |
|
501 | setTitleUsingUrl(url = "") {
|
502 | this.url = url;
|
503 | this.baseUrl = url.split("#")[0];
|
504 | let title = (0, _ui_utils.getPDFFileNameFromURL)(url, "");
|
505 |
|
506 | if (!title) {
|
507 | try {
|
508 | title = decodeURIComponent((0, _pdf.getFilenameFromUrl)(url)) || url;
|
509 | } catch (ex) {
|
510 | title = url;
|
511 | }
|
512 | }
|
513 |
|
514 | this.setTitle(title);
|
515 | },
|
516 |
|
517 | setTitle(title) {
|
518 | if (this.isViewerEmbedded) {
|
519 | return;
|
520 | }
|
521 |
|
522 | document.title = title;
|
523 | },
|
524 |
|
525 | async close() {
|
526 | const errorWrapper = this.appConfig.errorWrapper.container;
|
527 | errorWrapper.setAttribute("hidden", "true");
|
528 |
|
529 | if (!this.pdfLoadingTask) {
|
530 | return undefined;
|
531 | }
|
532 |
|
533 | const promise = this.pdfLoadingTask.destroy();
|
534 | this.pdfLoadingTask = null;
|
535 |
|
536 | if (this.pdfDocument) {
|
537 | this.pdfDocument = null;
|
538 | this.pdfThumbnailViewer.setDocument(null);
|
539 | this.pdfViewer.setDocument(null);
|
540 | this.pdfLinkService.setDocument(null);
|
541 | this.pdfDocumentProperties.setDocument(null);
|
542 | }
|
543 |
|
544 | this.store = null;
|
545 | this.isInitialViewSet = false;
|
546 | this.downloadComplete = false;
|
547 | this.url = "";
|
548 | this.baseUrl = "";
|
549 | this.contentDispositionFilename = null;
|
550 | this.pdfSidebar.reset();
|
551 | this.pdfOutlineViewer.reset();
|
552 | this.pdfAttachmentViewer.reset();
|
553 |
|
554 | if (this.pdfHistory) {
|
555 | this.pdfHistory.reset();
|
556 | }
|
557 |
|
558 | if (this.findBar) {
|
559 | this.findBar.reset();
|
560 | }
|
561 |
|
562 | this.toolbar.reset();
|
563 | this.secondaryToolbar.reset();
|
564 |
|
565 | if (typeof PDFBug !== "undefined") {
|
566 | PDFBug.cleanup();
|
567 | }
|
568 |
|
569 | return promise;
|
570 | },
|
571 |
|
572 | async open(file, args) {
|
573 | if (this.pdfLoadingTask) {
|
574 | await this.close();
|
575 | }
|
576 |
|
577 | const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
|
578 |
|
579 | for (const key in workerParameters) {
|
580 | _pdf.GlobalWorkerOptions[key] = workerParameters[key];
|
581 | }
|
582 |
|
583 | const parameters = Object.create(null);
|
584 |
|
585 | if (typeof file === "string") {
|
586 | this.setTitleUsingUrl(file);
|
587 | parameters.url = file;
|
588 | } else if (file && "byteLength" in file) {
|
589 | parameters.data = file;
|
590 | } else if (file.url && file.originalUrl) {
|
591 | this.setTitleUsingUrl(file.originalUrl);
|
592 | parameters.url = file.url;
|
593 | }
|
594 |
|
595 | const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
|
596 |
|
597 | for (const key in apiParameters) {
|
598 | let value = apiParameters[key];
|
599 |
|
600 | if (key === "docBaseUrl" && !value) {}
|
601 |
|
602 | parameters[key] = value;
|
603 | }
|
604 |
|
605 | if (args) {
|
606 | for (const key in args) {
|
607 | const value = args[key];
|
608 |
|
609 | if (key === "length") {
|
610 | this.pdfDocumentProperties.setFileSize(value);
|
611 | }
|
612 |
|
613 | parameters[key] = value;
|
614 | }
|
615 | }
|
616 |
|
617 | const loadingTask = (0, _pdf.getDocument)(parameters);
|
618 | this.pdfLoadingTask = loadingTask;
|
619 |
|
620 | loadingTask.onPassword = (updateCallback, reason) => {
|
621 | this.pdfLinkService.externalLinkEnabled = false;
|
622 | this.passwordPrompt.setUpdateCallback(updateCallback, reason);
|
623 | this.passwordPrompt.open();
|
624 | };
|
625 |
|
626 | loadingTask.onProgress = ({
|
627 | loaded,
|
628 | total
|
629 | }) => {
|
630 | this.progress(loaded / total);
|
631 | };
|
632 |
|
633 | loadingTask.onUnsupportedFeature = this.fallback.bind(this);
|
634 | return loadingTask.promise.then(pdfDocument => {
|
635 | this.load(pdfDocument);
|
636 | }, exception => {
|
637 | if (loadingTask !== this.pdfLoadingTask) {
|
638 | return undefined;
|
639 | }
|
640 |
|
641 | const message = exception && exception.message;
|
642 | let loadingErrorMessage;
|
643 |
|
644 | if (exception instanceof _pdf.InvalidPDFException) {
|
645 | loadingErrorMessage = this.l10n.get("invalid_file_error", null, "Invalid or corrupted PDF file.");
|
646 | } else if (exception instanceof _pdf.MissingPDFException) {
|
647 | loadingErrorMessage = this.l10n.get("missing_file_error", null, "Missing PDF file.");
|
648 | } else if (exception instanceof _pdf.UnexpectedResponseException) {
|
649 | loadingErrorMessage = this.l10n.get("unexpected_response_error", null, "Unexpected server response.");
|
650 | } else {
|
651 | loadingErrorMessage = this.l10n.get("loading_error", null, "An error occurred while loading the PDF.");
|
652 | }
|
653 |
|
654 | return loadingErrorMessage.then(msg => {
|
655 | this.error(msg, {
|
656 | message
|
657 | });
|
658 | throw new Error(msg);
|
659 | });
|
660 | });
|
661 | },
|
662 |
|
663 | download() {
|
664 | function downloadByUrl() {
|
665 | downloadManager.downloadUrl(url, filename);
|
666 | }
|
667 |
|
668 | const url = this.baseUrl;
|
669 | const filename = this.contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
|
670 | const downloadManager = this.downloadManager;
|
671 |
|
672 | downloadManager.onerror = err => {
|
673 | this.error(`PDF failed to download: ${err}`);
|
674 | };
|
675 |
|
676 | if (!this.pdfDocument || !this.downloadComplete) {
|
677 | downloadByUrl();
|
678 | return;
|
679 | }
|
680 |
|
681 | this.pdfDocument.getData().then(function (data) {
|
682 | const blob = new Blob([data], {
|
683 | type: "application/pdf"
|
684 | });
|
685 | downloadManager.download(blob, url, filename);
|
686 | }).catch(downloadByUrl);
|
687 | },
|
688 |
|
689 | fallback(featureId) {
|
690 | if (this.fellback) {
|
691 | return;
|
692 | }
|
693 |
|
694 | this.fellback = true;
|
695 | this.externalServices.fallback({
|
696 | featureId,
|
697 | url: this.baseUrl
|
698 | }, function response(download) {
|
699 | if (!download) {
|
700 | return;
|
701 | }
|
702 |
|
703 | PDFViewerApplication.download();
|
704 | });
|
705 | },
|
706 |
|
707 | error(message, moreInfo) {
|
708 | const moreInfoText = [this.l10n.get("error_version_info", {
|
709 | version: _pdf.version || "?",
|
710 | build: _pdf.build || "?"
|
711 | }, "PDF.js v{{version}} (build: {{build}})")];
|
712 |
|
713 | if (moreInfo) {
|
714 | moreInfoText.push(this.l10n.get("error_message", {
|
715 | message: moreInfo.message
|
716 | }, "Message: {{message}}"));
|
717 |
|
718 | if (moreInfo.stack) {
|
719 | moreInfoText.push(this.l10n.get("error_stack", {
|
720 | stack: moreInfo.stack
|
721 | }, "Stack: {{stack}}"));
|
722 | } else {
|
723 | if (moreInfo.filename) {
|
724 | moreInfoText.push(this.l10n.get("error_file", {
|
725 | file: moreInfo.filename
|
726 | }, "File: {{file}}"));
|
727 | }
|
728 |
|
729 | if (moreInfo.lineNumber) {
|
730 | moreInfoText.push(this.l10n.get("error_line", {
|
731 | line: moreInfo.lineNumber
|
732 | }, "Line: {{line}}"));
|
733 | }
|
734 | }
|
735 | }
|
736 |
|
737 | const errorWrapperConfig = this.appConfig.errorWrapper;
|
738 | const errorWrapper = errorWrapperConfig.container;
|
739 | errorWrapper.removeAttribute("hidden");
|
740 | const errorMessage = errorWrapperConfig.errorMessage;
|
741 | errorMessage.textContent = message;
|
742 | const closeButton = errorWrapperConfig.closeButton;
|
743 |
|
744 | closeButton.onclick = function () {
|
745 | errorWrapper.setAttribute("hidden", "true");
|
746 | };
|
747 |
|
748 | const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
|
749 | const moreInfoButton = errorWrapperConfig.moreInfoButton;
|
750 | const lessInfoButton = errorWrapperConfig.lessInfoButton;
|
751 |
|
752 | moreInfoButton.onclick = function () {
|
753 | errorMoreInfo.removeAttribute("hidden");
|
754 | moreInfoButton.setAttribute("hidden", "true");
|
755 | lessInfoButton.removeAttribute("hidden");
|
756 | errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
|
757 | };
|
758 |
|
759 | lessInfoButton.onclick = function () {
|
760 | errorMoreInfo.setAttribute("hidden", "true");
|
761 | moreInfoButton.removeAttribute("hidden");
|
762 | lessInfoButton.setAttribute("hidden", "true");
|
763 | };
|
764 |
|
765 | moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
|
766 | lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
|
767 | closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
|
768 | moreInfoButton.removeAttribute("hidden");
|
769 | lessInfoButton.setAttribute("hidden", "true");
|
770 | Promise.all(moreInfoText).then(parts => {
|
771 | errorMoreInfo.value = parts.join("\n");
|
772 | });
|
773 | },
|
774 |
|
775 | progress(level) {
|
776 | if (this.downloadComplete) {
|
777 | return;
|
778 | }
|
779 |
|
780 | const percent = Math.round(level * 100);
|
781 |
|
782 | if (percent > this.loadingBar.percent || isNaN(percent)) {
|
783 | this.loadingBar.percent = percent;
|
784 | const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams["disableAutoFetch"] : _app_options.AppOptions.get("disableAutoFetch");
|
785 |
|
786 | if (disableAutoFetch && percent) {
|
787 | if (this.disableAutoFetchLoadingBarTimeout) {
|
788 | clearTimeout(this.disableAutoFetchLoadingBarTimeout);
|
789 | this.disableAutoFetchLoadingBarTimeout = null;
|
790 | }
|
791 |
|
792 | this.loadingBar.show();
|
793 | this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
|
794 | this.loadingBar.hide();
|
795 | this.disableAutoFetchLoadingBarTimeout = null;
|
796 | }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
|
797 | }
|
798 | }
|
799 | },
|
800 |
|
801 | load(pdfDocument) {
|
802 | this.pdfDocument = pdfDocument;
|
803 | pdfDocument.getDownloadInfo().then(() => {
|
804 | this.downloadComplete = true;
|
805 | this.loadingBar.hide();
|
806 | firstPagePromise.then(() => {
|
807 | this.eventBus.dispatch("documentloaded", {
|
808 | source: this
|
809 | });
|
810 | });
|
811 | });
|
812 | const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
|
813 | const pageModePromise = pdfDocument.getPageMode().catch(function () {});
|
814 | const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
|
815 | this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
816 | this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
|
817 | const store = this.store = new _view_history.ViewHistory(pdfDocument.fingerprint);
|
818 | let baseDocumentUrl;
|
819 | baseDocumentUrl = null;
|
820 | this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
821 | this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
|
822 | const pdfViewer = this.pdfViewer;
|
823 | pdfViewer.setDocument(pdfDocument);
|
824 | const {
|
825 | firstPagePromise,
|
826 | onePageRendered,
|
827 | pagesPromise
|
828 | } = pdfViewer;
|
829 | const pdfThumbnailViewer = this.pdfThumbnailViewer;
|
830 | pdfThumbnailViewer.setDocument(pdfDocument);
|
831 | firstPagePromise.then(pdfPage => {
|
832 | this.loadingBar.setWidth(this.appConfig.viewerContainer);
|
833 | const storePromise = store.getMultiple({
|
834 | page: null,
|
835 | zoom: _ui_utils.DEFAULT_SCALE_VALUE,
|
836 | scrollLeft: "0",
|
837 | scrollTop: "0",
|
838 | rotation: null,
|
839 | sidebarView: _pdf_sidebar.SidebarView.UNKNOWN,
|
840 | scrollMode: _ui_utils.ScrollMode.UNKNOWN,
|
841 | spreadMode: _ui_utils.SpreadMode.UNKNOWN
|
842 | }).catch(() => {});
|
843 | Promise.all([_ui_utils.animationStarted, storePromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, values = {}, pageLayout, pageMode, openAction]) => {
|
844 | const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
|
845 |
|
846 | this._initializePdfHistory({
|
847 | fingerprint: pdfDocument.fingerprint,
|
848 | viewOnLoad,
|
849 | initialDest: openAction && openAction.dest
|
850 | });
|
851 |
|
852 | const initialBookmark = this.initialBookmark;
|
853 |
|
854 | const zoom = _app_options.AppOptions.get("defaultZoomValue");
|
855 |
|
856 | let hash = zoom ? `zoom=${zoom}` : null;
|
857 | let rotation = null;
|
858 |
|
859 | let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
|
860 |
|
861 | let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
|
862 |
|
863 | let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
|
864 |
|
865 | if (values.page && viewOnLoad !== ViewOnLoad.INITIAL) {
|
866 | hash = `page=${values.page}&zoom=${zoom || values.zoom},` + `${values.scrollLeft},${values.scrollTop}`;
|
867 | rotation = parseInt(values.rotation, 10);
|
868 |
|
869 | if (sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
|
870 | sidebarView = values.sidebarView | 0;
|
871 | }
|
872 |
|
873 | if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
|
874 | scrollMode = values.scrollMode | 0;
|
875 | }
|
876 |
|
877 | if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
|
878 | spreadMode = values.spreadMode | 0;
|
879 | }
|
880 | }
|
881 |
|
882 | if (pageMode && sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
|
883 | sidebarView = apiPageModeToSidebarView(pageMode);
|
884 | }
|
885 |
|
886 | if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
|
887 | spreadMode = apiPageLayoutToSpreadMode(pageLayout);
|
888 | }
|
889 |
|
890 | this.setInitialView(hash, {
|
891 | rotation,
|
892 | sidebarView,
|
893 | scrollMode,
|
894 | spreadMode
|
895 | });
|
896 | this.eventBus.dispatch("documentinit", {
|
897 | source: this
|
898 | });
|
899 |
|
900 | if (!this.isViewerEmbedded) {
|
901 | pdfViewer.focus();
|
902 | }
|
903 |
|
904 | await Promise.race([pagesPromise, new Promise(resolve => {
|
905 | setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
|
906 | })]);
|
907 |
|
908 | if (!initialBookmark && !hash) {
|
909 | return;
|
910 | }
|
911 |
|
912 | if (pdfViewer.hasEqualPageSizes) {
|
913 | return;
|
914 | }
|
915 |
|
916 | this.initialBookmark = initialBookmark;
|
917 | pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
|
918 | this.setInitialView(hash);
|
919 | }).catch(() => {
|
920 | this.setInitialView();
|
921 | }).then(function () {
|
922 | pdfViewer.update();
|
923 | });
|
924 | });
|
925 | pdfDocument.getPageLabels().then(labels => {
|
926 | if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
|
927 | return;
|
928 | }
|
929 |
|
930 | const numLabels = labels.length;
|
931 |
|
932 | if (numLabels !== this.pagesCount) {
|
933 | console.error("The number of Page Labels does not match " + "the number of pages in the document.");
|
934 | return;
|
935 | }
|
936 |
|
937 | let i = 0;
|
938 |
|
939 | while (i < numLabels && labels[i] === (i + 1).toString()) {
|
940 | i++;
|
941 | }
|
942 |
|
943 | if (i === numLabels) {
|
944 | return;
|
945 | }
|
946 |
|
947 | pdfViewer.setPageLabels(labels);
|
948 | pdfThumbnailViewer.setPageLabels(labels);
|
949 | this.toolbar.setPagesCount(pdfDocument.numPages, true);
|
950 | this.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
|
951 | });
|
952 | pagesPromise.then(async () => {
|
953 | const [openAction, javaScript] = await Promise.all([openActionPromise, pdfDocument.getJavaScript()]);
|
954 | let triggerAutoPrint = false;
|
955 |
|
956 | if (openAction && openAction.action === "Print") {
|
957 | triggerAutoPrint = true;
|
958 | }
|
959 |
|
960 | if (javaScript) {
|
961 | javaScript.some(js => {
|
962 | if (!js) {
|
963 | return false;
|
964 | }
|
965 |
|
966 | console.warn("Warning: JavaScript is not supported");
|
967 | this.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
|
968 | return true;
|
969 | });
|
970 |
|
971 | if (!triggerAutoPrint) {
|
972 | for (const js of javaScript) {
|
973 | if (js && _ui_utils.AutoPrintRegExp.test(js)) {
|
974 | triggerAutoPrint = true;
|
975 | break;
|
976 | }
|
977 | }
|
978 | }
|
979 | }
|
980 |
|
981 | if (!this.supportsPrinting) {
|
982 | return;
|
983 | }
|
984 |
|
985 | if (triggerAutoPrint) {
|
986 | setTimeout(function () {
|
987 | window.print();
|
988 | });
|
989 | }
|
990 | });
|
991 | onePageRendered.then(() => {
|
992 | pdfDocument.getOutline().then(outline => {
|
993 | this.pdfOutlineViewer.render({
|
994 | outline
|
995 | });
|
996 | });
|
997 | pdfDocument.getAttachments().then(attachments => {
|
998 | this.pdfAttachmentViewer.render({
|
999 | attachments
|
1000 | });
|
1001 | });
|
1002 | });
|
1003 | pdfDocument.getMetadata().then(({
|
1004 | info,
|
1005 | metadata,
|
1006 | contentDispositionFilename
|
1007 | }) => {
|
1008 | this.documentInfo = info;
|
1009 | this.metadata = metadata;
|
1010 | this.contentDispositionFilename = contentDispositionFilename;
|
1011 | console.log("PDF " + pdfDocument.fingerprint + " [" + info.PDFFormatVersion + " " + (info.Producer || "-").trim() + " / " + (info.Creator || "-").trim() + "]" + " (PDF.js: " + (_pdf.version || "-") + (_app_options.AppOptions.get("enableWebGL") ? " [WebGL]" : "") + ")");
|
1012 | let pdfTitle;
|
1013 | const infoTitle = info && info["Title"];
|
1014 |
|
1015 | if (infoTitle) {
|
1016 | pdfTitle = infoTitle;
|
1017 | }
|
1018 |
|
1019 | const metadataTitle = metadata && metadata.get("dc:title");
|
1020 |
|
1021 | if (metadataTitle) {
|
1022 | if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
|
1023 | pdfTitle = metadataTitle;
|
1024 | }
|
1025 | }
|
1026 |
|
1027 | if (pdfTitle) {
|
1028 | this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
|
1029 | } else if (contentDispositionFilename) {
|
1030 | this.setTitle(contentDispositionFilename);
|
1031 | }
|
1032 |
|
1033 | if (info.IsAcroFormPresent) {
|
1034 | console.warn("Warning: AcroForm/XFA is not supported");
|
1035 | this.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
|
1036 | }
|
1037 |
|
1038 | let versionId = "other";
|
1039 | 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"];
|
1040 |
|
1041 | if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
|
1042 | versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
|
1043 | }
|
1044 |
|
1045 | let generatorId = "other";
|
1046 | 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"];
|
1047 |
|
1048 | if (info.Producer) {
|
1049 | const producer = info.Producer.toLowerCase();
|
1050 | KNOWN_GENERATORS.some(function (generator) {
|
1051 | if (!producer.includes(generator)) {
|
1052 | return false;
|
1053 | }
|
1054 |
|
1055 | generatorId = generator.replace(/[ .\-]/g, "_");
|
1056 | return true;
|
1057 | });
|
1058 | }
|
1059 |
|
1060 | let formType = null;
|
1061 |
|
1062 | if (info.IsAcroFormPresent) {
|
1063 | formType = info.IsXFAPresent ? "xfa" : "acroform";
|
1064 | }
|
1065 |
|
1066 | this.externalServices.reportTelemetry({
|
1067 | type: "documentInfo",
|
1068 | version: versionId,
|
1069 | generator: generatorId,
|
1070 | formType
|
1071 | });
|
1072 | });
|
1073 | },
|
1074 |
|
1075 | _initializePdfHistory({
|
1076 | fingerprint,
|
1077 | viewOnLoad,
|
1078 | initialDest = null
|
1079 | }) {
|
1080 | if (_app_options.AppOptions.get("disableHistory") || this.isViewerEmbedded) {
|
1081 | return;
|
1082 | }
|
1083 |
|
1084 | this.pdfHistory.initialize({
|
1085 | fingerprint,
|
1086 | resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
|
1087 | updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
|
1088 | });
|
1089 |
|
1090 | if (this.pdfHistory.initialBookmark) {
|
1091 | this.initialBookmark = this.pdfHistory.initialBookmark;
|
1092 | this.initialRotation = this.pdfHistory.initialRotation;
|
1093 | }
|
1094 |
|
1095 | if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
|
1096 | this.initialBookmark = JSON.stringify(initialDest);
|
1097 | this.pdfHistory.push({
|
1098 | explicitDest: initialDest,
|
1099 | pageNumber: null
|
1100 | });
|
1101 | }
|
1102 | },
|
1103 |
|
1104 | setInitialView(storedHash, {
|
1105 | rotation,
|
1106 | sidebarView,
|
1107 | scrollMode,
|
1108 | spreadMode
|
1109 | } = {}) {
|
1110 | const setRotation = angle => {
|
1111 | if ((0, _ui_utils.isValidRotation)(angle)) {
|
1112 | this.pdfViewer.pagesRotation = angle;
|
1113 | }
|
1114 | };
|
1115 |
|
1116 | const setViewerModes = (scroll, spread) => {
|
1117 | if ((0, _ui_utils.isValidScrollMode)(scroll)) {
|
1118 | this.pdfViewer.scrollMode = scroll;
|
1119 | }
|
1120 |
|
1121 | if ((0, _ui_utils.isValidSpreadMode)(spread)) {
|
1122 | this.pdfViewer.spreadMode = spread;
|
1123 | }
|
1124 | };
|
1125 |
|
1126 | this.isInitialViewSet = true;
|
1127 | this.pdfSidebar.setInitialView(sidebarView);
|
1128 | setViewerModes(scrollMode, spreadMode);
|
1129 |
|
1130 | if (this.initialBookmark) {
|
1131 | setRotation(this.initialRotation);
|
1132 | delete this.initialRotation;
|
1133 | this.pdfLinkService.setHash(this.initialBookmark);
|
1134 | this.initialBookmark = null;
|
1135 | } else if (storedHash) {
|
1136 | setRotation(rotation);
|
1137 | this.pdfLinkService.setHash(storedHash);
|
1138 | }
|
1139 |
|
1140 | this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
|
1141 | this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
|
1142 |
|
1143 | if (!this.pdfViewer.currentScaleValue) {
|
1144 | this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
|
1145 | }
|
1146 | },
|
1147 |
|
1148 | cleanup() {
|
1149 | if (!this.pdfDocument) {
|
1150 | return;
|
1151 | }
|
1152 |
|
1153 | this.pdfViewer.cleanup();
|
1154 | this.pdfThumbnailViewer.cleanup();
|
1155 |
|
1156 | if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
|
1157 | this.pdfDocument.cleanup();
|
1158 | }
|
1159 | },
|
1160 |
|
1161 | forceRendering() {
|
1162 | this.pdfRenderingQueue.printing = this.printing;
|
1163 | this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
|
1164 | this.pdfRenderingQueue.renderHighestPriority();
|
1165 | },
|
1166 |
|
1167 | beforePrint() {
|
1168 | if (this.printService) {
|
1169 | return;
|
1170 | }
|
1171 |
|
1172 | if (!this.supportsPrinting) {
|
1173 | this.l10n.get("printing_not_supported", null, "Warning: Printing is not fully supported by this browser.").then(printMessage => {
|
1174 | this.error(printMessage);
|
1175 | });
|
1176 | return;
|
1177 | }
|
1178 |
|
1179 | if (!this.pdfViewer.pageViewsReady) {
|
1180 | this.l10n.get("printing_not_ready", null, "Warning: The PDF is not fully loaded for printing.").then(notReadyMessage => {
|
1181 | window.alert(notReadyMessage);
|
1182 | });
|
1183 | return;
|
1184 | }
|
1185 |
|
1186 | const pagesOverview = this.pdfViewer.getPagesOverview();
|
1187 | const printContainer = this.appConfig.printContainer;
|
1188 | const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
|
1189 | this.printService = printService;
|
1190 | this.forceRendering();
|
1191 | printService.layout();
|
1192 | this.externalServices.reportTelemetry({
|
1193 | type: "print"
|
1194 | });
|
1195 | },
|
1196 |
|
1197 | afterPrint() {
|
1198 | if (this.printService) {
|
1199 | this.printService.destroy();
|
1200 | this.printService = null;
|
1201 | }
|
1202 |
|
1203 | this.forceRendering();
|
1204 | },
|
1205 |
|
1206 | rotatePages(delta) {
|
1207 | if (!this.pdfDocument) {
|
1208 | return;
|
1209 | }
|
1210 |
|
1211 | const newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
|
1212 | this.pdfViewer.pagesRotation = newRotation;
|
1213 | },
|
1214 |
|
1215 | requestPresentationMode() {
|
1216 | if (!this.pdfPresentationMode) {
|
1217 | return;
|
1218 | }
|
1219 |
|
1220 | this.pdfPresentationMode.request();
|
1221 | },
|
1222 |
|
1223 | bindEvents() {
|
1224 | const {
|
1225 | eventBus,
|
1226 | _boundEvents
|
1227 | } = this;
|
1228 | _boundEvents.beforePrint = this.beforePrint.bind(this);
|
1229 | _boundEvents.afterPrint = this.afterPrint.bind(this);
|
1230 |
|
1231 | eventBus._on("resize", webViewerResize);
|
1232 |
|
1233 | eventBus._on("hashchange", webViewerHashchange);
|
1234 |
|
1235 | eventBus._on("beforeprint", _boundEvents.beforePrint);
|
1236 |
|
1237 | eventBus._on("afterprint", _boundEvents.afterPrint);
|
1238 |
|
1239 | eventBus._on("pagerendered", webViewerPageRendered);
|
1240 |
|
1241 | eventBus._on("updateviewarea", webViewerUpdateViewarea);
|
1242 |
|
1243 | eventBus._on("pagechanging", webViewerPageChanging);
|
1244 |
|
1245 | eventBus._on("scalechanging", webViewerScaleChanging);
|
1246 |
|
1247 | eventBus._on("rotationchanging", webViewerRotationChanging);
|
1248 |
|
1249 | eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
|
1250 |
|
1251 | eventBus._on("pagemode", webViewerPageMode);
|
1252 |
|
1253 | eventBus._on("namedaction", webViewerNamedAction);
|
1254 |
|
1255 | eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
|
1256 |
|
1257 | eventBus._on("presentationmode", webViewerPresentationMode);
|
1258 |
|
1259 | eventBus._on("print", webViewerPrint);
|
1260 |
|
1261 | eventBus._on("download", webViewerDownload);
|
1262 |
|
1263 | eventBus._on("firstpage", webViewerFirstPage);
|
1264 |
|
1265 | eventBus._on("lastpage", webViewerLastPage);
|
1266 |
|
1267 | eventBus._on("nextpage", webViewerNextPage);
|
1268 |
|
1269 | eventBus._on("previouspage", webViewerPreviousPage);
|
1270 |
|
1271 | eventBus._on("zoomin", webViewerZoomIn);
|
1272 |
|
1273 | eventBus._on("zoomout", webViewerZoomOut);
|
1274 |
|
1275 | eventBus._on("zoomreset", webViewerZoomReset);
|
1276 |
|
1277 | eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
|
1278 |
|
1279 | eventBus._on("scalechanged", webViewerScaleChanged);
|
1280 |
|
1281 | eventBus._on("rotatecw", webViewerRotateCw);
|
1282 |
|
1283 | eventBus._on("rotateccw", webViewerRotateCcw);
|
1284 |
|
1285 | eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
|
1286 |
|
1287 | eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
|
1288 |
|
1289 | eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
|
1290 |
|
1291 | eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
|
1292 |
|
1293 | eventBus._on("documentproperties", webViewerDocumentProperties);
|
1294 |
|
1295 | eventBus._on("find", webViewerFind);
|
1296 |
|
1297 | eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
|
1298 |
|
1299 | eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
|
1300 |
|
1301 | eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
|
1302 |
|
1303 | eventBus._on("fileinputchange", webViewerFileInputChange);
|
1304 |
|
1305 | eventBus._on("openfile", webViewerOpenFile);
|
1306 | },
|
1307 |
|
1308 | bindWindowEvents() {
|
1309 | const {
|
1310 | eventBus,
|
1311 | _boundEvents
|
1312 | } = this;
|
1313 |
|
1314 | _boundEvents.windowResize = () => {
|
1315 | eventBus.dispatch("resize", {
|
1316 | source: window
|
1317 | });
|
1318 | };
|
1319 |
|
1320 | _boundEvents.windowHashChange = () => {
|
1321 | eventBus.dispatch("hashchange", {
|
1322 | source: window,
|
1323 | hash: document.location.hash.substring(1)
|
1324 | });
|
1325 | };
|
1326 |
|
1327 | _boundEvents.windowBeforePrint = () => {
|
1328 | eventBus.dispatch("beforeprint", {
|
1329 | source: window
|
1330 | });
|
1331 | };
|
1332 |
|
1333 | _boundEvents.windowAfterPrint = () => {
|
1334 | eventBus.dispatch("afterprint", {
|
1335 | source: window
|
1336 | });
|
1337 | };
|
1338 |
|
1339 | window.addEventListener("visibilitychange", webViewerVisibilityChange);
|
1340 | window.addEventListener("wheel", webViewerWheel, {
|
1341 | passive: false
|
1342 | });
|
1343 | window.addEventListener("click", webViewerClick);
|
1344 | window.addEventListener("keydown", webViewerKeyDown);
|
1345 | window.addEventListener("resize", _boundEvents.windowResize);
|
1346 | window.addEventListener("hashchange", _boundEvents.windowHashChange);
|
1347 | window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
1348 | window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
|
1349 | },
|
1350 |
|
1351 | unbindEvents() {
|
1352 | const {
|
1353 | eventBus,
|
1354 | _boundEvents
|
1355 | } = this;
|
1356 |
|
1357 | eventBus._off("resize", webViewerResize);
|
1358 |
|
1359 | eventBus._off("hashchange", webViewerHashchange);
|
1360 |
|
1361 | eventBus._off("beforeprint", _boundEvents.beforePrint);
|
1362 |
|
1363 | eventBus._off("afterprint", _boundEvents.afterPrint);
|
1364 |
|
1365 | eventBus._off("pagerendered", webViewerPageRendered);
|
1366 |
|
1367 | eventBus._off("updateviewarea", webViewerUpdateViewarea);
|
1368 |
|
1369 | eventBus._off("pagechanging", webViewerPageChanging);
|
1370 |
|
1371 | eventBus._off("scalechanging", webViewerScaleChanging);
|
1372 |
|
1373 | eventBus._off("rotationchanging", webViewerRotationChanging);
|
1374 |
|
1375 | eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
|
1376 |
|
1377 | eventBus._off("pagemode", webViewerPageMode);
|
1378 |
|
1379 | eventBus._off("namedaction", webViewerNamedAction);
|
1380 |
|
1381 | eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
|
1382 |
|
1383 | eventBus._off("presentationmode", webViewerPresentationMode);
|
1384 |
|
1385 | eventBus._off("print", webViewerPrint);
|
1386 |
|
1387 | eventBus._off("download", webViewerDownload);
|
1388 |
|
1389 | eventBus._off("firstpage", webViewerFirstPage);
|
1390 |
|
1391 | eventBus._off("lastpage", webViewerLastPage);
|
1392 |
|
1393 | eventBus._off("nextpage", webViewerNextPage);
|
1394 |
|
1395 | eventBus._off("previouspage", webViewerPreviousPage);
|
1396 |
|
1397 | eventBus._off("zoomin", webViewerZoomIn);
|
1398 |
|
1399 | eventBus._off("zoomout", webViewerZoomOut);
|
1400 |
|
1401 | eventBus._off("zoomreset", webViewerZoomReset);
|
1402 |
|
1403 | eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
|
1404 |
|
1405 | eventBus._off("scalechanged", webViewerScaleChanged);
|
1406 |
|
1407 | eventBus._off("rotatecw", webViewerRotateCw);
|
1408 |
|
1409 | eventBus._off("rotateccw", webViewerRotateCcw);
|
1410 |
|
1411 | eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
|
1412 |
|
1413 | eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
|
1414 |
|
1415 | eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
|
1416 |
|
1417 | eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
|
1418 |
|
1419 | eventBus._off("documentproperties", webViewerDocumentProperties);
|
1420 |
|
1421 | eventBus._off("find", webViewerFind);
|
1422 |
|
1423 | eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
|
1424 |
|
1425 | eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
|
1426 |
|
1427 | eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
|
1428 |
|
1429 | eventBus._off("fileinputchange", webViewerFileInputChange);
|
1430 |
|
1431 | eventBus._off("openfile", webViewerOpenFile);
|
1432 |
|
1433 | _boundEvents.beforePrint = null;
|
1434 | _boundEvents.afterPrint = null;
|
1435 | },
|
1436 |
|
1437 | unbindWindowEvents() {
|
1438 | const {
|
1439 | _boundEvents
|
1440 | } = this;
|
1441 | window.removeEventListener("visibilitychange", webViewerVisibilityChange);
|
1442 | window.removeEventListener("wheel", webViewerWheel);
|
1443 | window.removeEventListener("click", webViewerClick);
|
1444 | window.removeEventListener("keydown", webViewerKeyDown);
|
1445 | window.removeEventListener("resize", _boundEvents.windowResize);
|
1446 | window.removeEventListener("hashchange", _boundEvents.windowHashChange);
|
1447 | window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
1448 | window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
|
1449 | _boundEvents.windowResize = null;
|
1450 | _boundEvents.windowHashChange = null;
|
1451 | _boundEvents.windowBeforePrint = null;
|
1452 | _boundEvents.windowAfterPrint = null;
|
1453 | }
|
1454 |
|
1455 | };
|
1456 | exports.PDFViewerApplication = PDFViewerApplication;
|
1457 | let validateFileURL;
|
1458 | {
|
1459 | const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
|
1460 |
|
1461 | validateFileURL = function (file) {
|
1462 | if (file === undefined) {
|
1463 | return;
|
1464 | }
|
1465 |
|
1466 | try {
|
1467 | const viewerOrigin = new URL(window.location.href).origin || "null";
|
1468 |
|
1469 | if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
|
1470 | return;
|
1471 | }
|
1472 |
|
1473 | const {
|
1474 | origin,
|
1475 | protocol
|
1476 | } = new URL(file, window.location.href);
|
1477 |
|
1478 | if (origin !== viewerOrigin && protocol !== "blob:") {
|
1479 | throw new Error("file origin does not match viewer's");
|
1480 | }
|
1481 | } catch (ex) {
|
1482 | const message = ex && ex.message;
|
1483 | PDFViewerApplication.l10n.get("loading_error", null, "An error occurred while loading the PDF.").then(loadingErrorMessage => {
|
1484 | PDFViewerApplication.error(loadingErrorMessage, {
|
1485 | message
|
1486 | });
|
1487 | });
|
1488 | throw ex;
|
1489 | }
|
1490 | };
|
1491 | }
|
1492 |
|
1493 | async function loadFakeWorker() {
|
1494 | if (!_pdf.GlobalWorkerOptions.workerSrc) {
|
1495 | _pdf.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
|
1496 | }
|
1497 |
|
1498 | return (0, _pdf.loadScript)(_pdf.PDFWorker.getWorkerSrc());
|
1499 | }
|
1500 |
|
1501 | function loadAndEnablePDFBug(enabledTabs) {
|
1502 | const appConfig = PDFViewerApplication.appConfig;
|
1503 | return (0, _pdf.loadScript)(appConfig.debuggerScriptPath).then(function () {
|
1504 | PDFBug.enable(enabledTabs);
|
1505 | PDFBug.init({
|
1506 | OPS: _pdf.OPS
|
1507 | }, appConfig.mainContainer);
|
1508 | });
|
1509 | }
|
1510 |
|
1511 | function webViewerInitialized() {
|
1512 | const appConfig = PDFViewerApplication.appConfig;
|
1513 | let file;
|
1514 | const queryString = document.location.search.substring(1);
|
1515 | const params = (0, _ui_utils.parseQueryString)(queryString);
|
1516 | file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
|
1517 | validateFileURL(file);
|
1518 | const fileInput = document.createElement("input");
|
1519 | fileInput.id = appConfig.openFileInputName;
|
1520 | fileInput.className = "fileInput";
|
1521 | fileInput.setAttribute("type", "file");
|
1522 | fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
|
1523 | document.body.appendChild(fileInput);
|
1524 |
|
1525 | if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
|
1526 | appConfig.toolbar.openFile.setAttribute("hidden", "true");
|
1527 | appConfig.secondaryToolbar.openFileButton.setAttribute("hidden", "true");
|
1528 | } else {
|
1529 | fileInput.value = null;
|
1530 | }
|
1531 |
|
1532 | fileInput.addEventListener("change", function (evt) {
|
1533 | const files = evt.target.files;
|
1534 |
|
1535 | if (!files || files.length === 0) {
|
1536 | return;
|
1537 | }
|
1538 |
|
1539 | PDFViewerApplication.eventBus.dispatch("fileinputchange", {
|
1540 | source: this,
|
1541 | fileInput: evt.target
|
1542 | });
|
1543 | });
|
1544 | appConfig.mainContainer.addEventListener("dragover", function (evt) {
|
1545 | evt.preventDefault();
|
1546 | evt.dataTransfer.dropEffect = "move";
|
1547 | });
|
1548 | appConfig.mainContainer.addEventListener("drop", function (evt) {
|
1549 | evt.preventDefault();
|
1550 | const files = evt.dataTransfer.files;
|
1551 |
|
1552 | if (!files || files.length === 0) {
|
1553 | return;
|
1554 | }
|
1555 |
|
1556 | PDFViewerApplication.eventBus.dispatch("fileinputchange", {
|
1557 | source: this,
|
1558 | fileInput: evt.dataTransfer
|
1559 | });
|
1560 | });
|
1561 |
|
1562 | if (!PDFViewerApplication.supportsDocumentFonts) {
|
1563 | _app_options.AppOptions.set("disableFontFace", true);
|
1564 |
|
1565 | PDFViewerApplication.l10n.get("web_fonts_disabled", null, "Web fonts are disabled: unable to use embedded PDF fonts.").then(msg => {
|
1566 | console.warn(msg);
|
1567 | });
|
1568 | }
|
1569 |
|
1570 | if (!PDFViewerApplication.supportsPrinting) {
|
1571 | appConfig.toolbar.print.classList.add("hidden");
|
1572 | appConfig.secondaryToolbar.printButton.classList.add("hidden");
|
1573 | }
|
1574 |
|
1575 | if (!PDFViewerApplication.supportsFullscreen) {
|
1576 | appConfig.toolbar.presentationModeButton.classList.add("hidden");
|
1577 | appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
|
1578 | }
|
1579 |
|
1580 | if (PDFViewerApplication.supportsIntegratedFind) {
|
1581 | appConfig.toolbar.viewFind.classList.add("hidden");
|
1582 | }
|
1583 |
|
1584 | appConfig.mainContainer.addEventListener("transitionend", function (evt) {
|
1585 | if (evt.target === this) {
|
1586 | PDFViewerApplication.eventBus.dispatch("resize", {
|
1587 | source: this
|
1588 | });
|
1589 | }
|
1590 | }, true);
|
1591 |
|
1592 | try {
|
1593 | webViewerOpenFileViaURL(file);
|
1594 | } catch (reason) {
|
1595 | PDFViewerApplication.l10n.get("loading_error", null, "An error occurred while loading the PDF.").then(msg => {
|
1596 | PDFViewerApplication.error(msg, reason);
|
1597 | });
|
1598 | }
|
1599 | }
|
1600 |
|
1601 | let webViewerOpenFileViaURL;
|
1602 | {
|
1603 | webViewerOpenFileViaURL = function (file) {
|
1604 | if (file && file.lastIndexOf("file:", 0) === 0) {
|
1605 | PDFViewerApplication.setTitleUsingUrl(file);
|
1606 | const xhr = new XMLHttpRequest();
|
1607 |
|
1608 | xhr.onload = function () {
|
1609 | PDFViewerApplication.open(new Uint8Array(xhr.response));
|
1610 | };
|
1611 |
|
1612 | xhr.open("GET", file);
|
1613 | xhr.responseType = "arraybuffer";
|
1614 | xhr.send();
|
1615 | return;
|
1616 | }
|
1617 |
|
1618 | if (file) {
|
1619 | PDFViewerApplication.open(file);
|
1620 | }
|
1621 | };
|
1622 | }
|
1623 |
|
1624 | function webViewerPageRendered(evt) {
|
1625 | const pageNumber = evt.pageNumber;
|
1626 | const pageIndex = pageNumber - 1;
|
1627 | const pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
1628 |
|
1629 | if (pageNumber === PDFViewerApplication.page) {
|
1630 | PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
|
1631 | }
|
1632 |
|
1633 | if (!pageView) {
|
1634 | return;
|
1635 | }
|
1636 |
|
1637 | if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
1638 | const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
|
1639 | thumbnailView.setImage(pageView);
|
1640 | }
|
1641 |
|
1642 | if (typeof Stats !== "undefined" && Stats.enabled && pageView.stats) {
|
1643 | Stats.add(pageNumber, pageView.stats);
|
1644 | }
|
1645 |
|
1646 | if (pageView.error) {
|
1647 | PDFViewerApplication.l10n.get("rendering_error", null, "An error occurred while rendering the page.").then(msg => {
|
1648 | PDFViewerApplication.error(msg, pageView.error);
|
1649 | });
|
1650 | }
|
1651 |
|
1652 | PDFViewerApplication.externalServices.reportTelemetry({
|
1653 | type: "pageInfo",
|
1654 | timestamp: evt.timestamp
|
1655 | });
|
1656 | PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
1657 | PDFViewerApplication.externalServices.reportTelemetry({
|
1658 | type: "documentStats",
|
1659 | stats
|
1660 | });
|
1661 | });
|
1662 | }
|
1663 |
|
1664 | function webViewerPageMode({
|
1665 | mode
|
1666 | }) {
|
1667 | let view;
|
1668 |
|
1669 | switch (mode) {
|
1670 | case "thumbs":
|
1671 | view = _pdf_sidebar.SidebarView.THUMBS;
|
1672 | break;
|
1673 |
|
1674 | case "bookmarks":
|
1675 | case "outline":
|
1676 | view = _pdf_sidebar.SidebarView.OUTLINE;
|
1677 | break;
|
1678 |
|
1679 | case "attachments":
|
1680 | view = _pdf_sidebar.SidebarView.ATTACHMENTS;
|
1681 | break;
|
1682 |
|
1683 | case "none":
|
1684 | view = _pdf_sidebar.SidebarView.NONE;
|
1685 | break;
|
1686 |
|
1687 | default:
|
1688 | console.error('Invalid "pagemode" hash parameter: ' + mode);
|
1689 | return;
|
1690 | }
|
1691 |
|
1692 | PDFViewerApplication.pdfSidebar.switchView(view, true);
|
1693 | }
|
1694 |
|
1695 | function webViewerNamedAction(evt) {
|
1696 | const action = evt.action;
|
1697 |
|
1698 | switch (action) {
|
1699 | case "GoToPage":
|
1700 | PDFViewerApplication.appConfig.toolbar.pageNumber.select();
|
1701 | break;
|
1702 |
|
1703 | case "Find":
|
1704 | if (!PDFViewerApplication.supportsIntegratedFind) {
|
1705 | PDFViewerApplication.findBar.toggle();
|
1706 | }
|
1707 |
|
1708 | break;
|
1709 | }
|
1710 | }
|
1711 |
|
1712 | function webViewerPresentationModeChanged({
|
1713 | active,
|
1714 | switchInProgress
|
1715 | }) {
|
1716 | let state = _ui_utils.PresentationModeState.NORMAL;
|
1717 |
|
1718 | if (switchInProgress) {
|
1719 | state = _ui_utils.PresentationModeState.CHANGING;
|
1720 | } else if (active) {
|
1721 | state = _ui_utils.PresentationModeState.FULLSCREEN;
|
1722 | }
|
1723 |
|
1724 | PDFViewerApplication.pdfViewer.presentationModeState = state;
|
1725 | }
|
1726 |
|
1727 | function webViewerSidebarViewChanged(evt) {
|
1728 | PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
|
1729 | const store = PDFViewerApplication.store;
|
1730 |
|
1731 | if (store && PDFViewerApplication.isInitialViewSet) {
|
1732 | store.set("sidebarView", evt.view).catch(function () {});
|
1733 | }
|
1734 | }
|
1735 |
|
1736 | function webViewerUpdateViewarea(evt) {
|
1737 | const location = evt.location,
|
1738 | store = PDFViewerApplication.store;
|
1739 |
|
1740 | if (store && PDFViewerApplication.isInitialViewSet) {
|
1741 | store.setMultiple({
|
1742 | page: location.pageNumber,
|
1743 | zoom: location.scale,
|
1744 | scrollLeft: location.left,
|
1745 | scrollTop: location.top,
|
1746 | rotation: location.rotation
|
1747 | }).catch(function () {});
|
1748 | }
|
1749 |
|
1750 | const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
|
1751 | PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
|
1752 | PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
|
1753 | const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
|
1754 | const loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
|
1755 | PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
|
1756 | }
|
1757 |
|
1758 | function webViewerScrollModeChanged(evt) {
|
1759 | const store = PDFViewerApplication.store;
|
1760 |
|
1761 | if (store && PDFViewerApplication.isInitialViewSet) {
|
1762 | store.set("scrollMode", evt.mode).catch(function () {});
|
1763 | }
|
1764 | }
|
1765 |
|
1766 | function webViewerSpreadModeChanged(evt) {
|
1767 | const store = PDFViewerApplication.store;
|
1768 |
|
1769 | if (store && PDFViewerApplication.isInitialViewSet) {
|
1770 | store.set("spreadMode", evt.mode).catch(function () {});
|
1771 | }
|
1772 | }
|
1773 |
|
1774 | function webViewerResize() {
|
1775 | const {
|
1776 | pdfDocument,
|
1777 | pdfViewer
|
1778 | } = PDFViewerApplication;
|
1779 |
|
1780 | if (!pdfDocument) {
|
1781 | return;
|
1782 | }
|
1783 |
|
1784 | const currentScaleValue = pdfViewer.currentScaleValue;
|
1785 |
|
1786 | if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
|
1787 | pdfViewer.currentScaleValue = currentScaleValue;
|
1788 | }
|
1789 |
|
1790 | pdfViewer.update();
|
1791 | }
|
1792 |
|
1793 | function webViewerHashchange(evt) {
|
1794 | const hash = evt.hash;
|
1795 |
|
1796 | if (!hash) {
|
1797 | return;
|
1798 | }
|
1799 |
|
1800 | if (!PDFViewerApplication.isInitialViewSet) {
|
1801 | PDFViewerApplication.initialBookmark = hash;
|
1802 | } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
|
1803 | PDFViewerApplication.pdfLinkService.setHash(hash);
|
1804 | }
|
1805 | }
|
1806 |
|
1807 | let webViewerFileInputChange, webViewerOpenFile;
|
1808 | {
|
1809 | webViewerFileInputChange = function (evt) {
|
1810 | if (PDFViewerApplication.pdfViewer && PDFViewerApplication.pdfViewer.isInPresentationMode) {
|
1811 | return;
|
1812 | }
|
1813 |
|
1814 | const file = evt.fileInput.files[0];
|
1815 |
|
1816 | if (URL.createObjectURL && !_app_options.AppOptions.get("disableCreateObjectURL")) {
|
1817 | let url = URL.createObjectURL(file);
|
1818 |
|
1819 | if (file.name) {
|
1820 | url = {
|
1821 | url,
|
1822 | originalUrl: file.name
|
1823 | };
|
1824 | }
|
1825 |
|
1826 | PDFViewerApplication.open(url);
|
1827 | } else {
|
1828 | PDFViewerApplication.setTitleUsingUrl(file.name);
|
1829 | const fileReader = new FileReader();
|
1830 |
|
1831 | fileReader.onload = function webViewerChangeFileReaderOnload(event) {
|
1832 | const buffer = event.target.result;
|
1833 | PDFViewerApplication.open(new Uint8Array(buffer));
|
1834 | };
|
1835 |
|
1836 | fileReader.readAsArrayBuffer(file);
|
1837 | }
|
1838 |
|
1839 | const appConfig = PDFViewerApplication.appConfig;
|
1840 | appConfig.toolbar.viewBookmark.setAttribute("hidden", "true");
|
1841 | appConfig.secondaryToolbar.viewBookmarkButton.setAttribute("hidden", "true");
|
1842 | appConfig.toolbar.download.setAttribute("hidden", "true");
|
1843 | appConfig.secondaryToolbar.downloadButton.setAttribute("hidden", "true");
|
1844 | };
|
1845 |
|
1846 | webViewerOpenFile = function (evt) {
|
1847 | const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
|
1848 | document.getElementById(openFileInputName).click();
|
1849 | };
|
1850 | }
|
1851 |
|
1852 | function webViewerPresentationMode() {
|
1853 | PDFViewerApplication.requestPresentationMode();
|
1854 | }
|
1855 |
|
1856 | function webViewerPrint() {
|
1857 | window.print();
|
1858 | }
|
1859 |
|
1860 | function webViewerDownload() {
|
1861 | PDFViewerApplication.download();
|
1862 | }
|
1863 |
|
1864 | function webViewerFirstPage() {
|
1865 | if (PDFViewerApplication.pdfDocument) {
|
1866 | PDFViewerApplication.page = 1;
|
1867 | }
|
1868 | }
|
1869 |
|
1870 | function webViewerLastPage() {
|
1871 | if (PDFViewerApplication.pdfDocument) {
|
1872 | PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
1873 | }
|
1874 | }
|
1875 |
|
1876 | function webViewerNextPage() {
|
1877 | PDFViewerApplication.page++;
|
1878 | }
|
1879 |
|
1880 | function webViewerPreviousPage() {
|
1881 | PDFViewerApplication.page--;
|
1882 | }
|
1883 |
|
1884 | function webViewerZoomIn() {
|
1885 | PDFViewerApplication.zoomIn();
|
1886 | }
|
1887 |
|
1888 | function webViewerZoomOut() {
|
1889 | PDFViewerApplication.zoomOut();
|
1890 | }
|
1891 |
|
1892 | function webViewerZoomReset() {
|
1893 | PDFViewerApplication.zoomReset();
|
1894 | }
|
1895 |
|
1896 | function webViewerPageNumberChanged(evt) {
|
1897 | const pdfViewer = PDFViewerApplication.pdfViewer;
|
1898 |
|
1899 | if (evt.value !== "") {
|
1900 | pdfViewer.currentPageLabel = evt.value;
|
1901 | }
|
1902 |
|
1903 | if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
|
1904 | PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
|
1905 | }
|
1906 | }
|
1907 |
|
1908 | function webViewerScaleChanged(evt) {
|
1909 | PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
|
1910 | }
|
1911 |
|
1912 | function webViewerRotateCw() {
|
1913 | PDFViewerApplication.rotatePages(90);
|
1914 | }
|
1915 |
|
1916 | function webViewerRotateCcw() {
|
1917 | PDFViewerApplication.rotatePages(-90);
|
1918 | }
|
1919 |
|
1920 | function webViewerSwitchScrollMode(evt) {
|
1921 | PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
|
1922 | }
|
1923 |
|
1924 | function webViewerSwitchSpreadMode(evt) {
|
1925 | PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
|
1926 | }
|
1927 |
|
1928 | function webViewerDocumentProperties() {
|
1929 | PDFViewerApplication.pdfDocumentProperties.open();
|
1930 | }
|
1931 |
|
1932 | function webViewerFind(evt) {
|
1933 | PDFViewerApplication.findController.executeCommand("find" + evt.type, {
|
1934 | query: evt.query,
|
1935 | phraseSearch: evt.phraseSearch,
|
1936 | caseSensitive: evt.caseSensitive,
|
1937 | entireWord: evt.entireWord,
|
1938 | highlightAll: evt.highlightAll,
|
1939 | findPrevious: evt.findPrevious
|
1940 | });
|
1941 | }
|
1942 |
|
1943 | function webViewerFindFromUrlHash(evt) {
|
1944 | PDFViewerApplication.findController.executeCommand("find", {
|
1945 | query: evt.query,
|
1946 | phraseSearch: evt.phraseSearch,
|
1947 | caseSensitive: false,
|
1948 | entireWord: false,
|
1949 | highlightAll: true,
|
1950 | findPrevious: false
|
1951 | });
|
1952 | }
|
1953 |
|
1954 | function webViewerUpdateFindMatchesCount({
|
1955 | matchesCount
|
1956 | }) {
|
1957 | if (PDFViewerApplication.supportsIntegratedFind) {
|
1958 | PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
|
1959 | } else {
|
1960 | PDFViewerApplication.findBar.updateResultsCount(matchesCount);
|
1961 | }
|
1962 | }
|
1963 |
|
1964 | function webViewerUpdateFindControlState({
|
1965 | state,
|
1966 | previous,
|
1967 | matchesCount
|
1968 | }) {
|
1969 | if (PDFViewerApplication.supportsIntegratedFind) {
|
1970 | PDFViewerApplication.externalServices.updateFindControlState({
|
1971 | result: state,
|
1972 | findPrevious: previous,
|
1973 | matchesCount
|
1974 | });
|
1975 | } else {
|
1976 | PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
|
1977 | }
|
1978 | }
|
1979 |
|
1980 | function webViewerScaleChanging(evt) {
|
1981 | PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
|
1982 | PDFViewerApplication.pdfViewer.update();
|
1983 | }
|
1984 |
|
1985 | function webViewerRotationChanging(evt) {
|
1986 | PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
|
1987 | PDFViewerApplication.forceRendering();
|
1988 | PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
|
1989 | }
|
1990 |
|
1991 | function webViewerPageChanging(evt) {
|
1992 | const page = evt.pageNumber;
|
1993 | PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
|
1994 | PDFViewerApplication.secondaryToolbar.setPageNumber(page);
|
1995 |
|
1996 | if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
1997 | PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
|
1998 | }
|
1999 |
|
2000 | if (typeof Stats !== "undefined" && Stats.enabled) {
|
2001 | const pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
|
2002 |
|
2003 | if (pageView && pageView.stats) {
|
2004 | Stats.add(page, pageView.stats);
|
2005 | }
|
2006 | }
|
2007 | }
|
2008 |
|
2009 | function webViewerVisibilityChange(evt) {
|
2010 | if (document.visibilityState === "visible") {
|
2011 | setZoomDisabledTimeout();
|
2012 | }
|
2013 | }
|
2014 |
|
2015 | let zoomDisabledTimeout = null;
|
2016 |
|
2017 | function setZoomDisabledTimeout() {
|
2018 | if (zoomDisabledTimeout) {
|
2019 | clearTimeout(zoomDisabledTimeout);
|
2020 | }
|
2021 |
|
2022 | zoomDisabledTimeout = setTimeout(function () {
|
2023 | zoomDisabledTimeout = null;
|
2024 | }, WHEEL_ZOOM_DISABLED_TIMEOUT);
|
2025 | }
|
2026 |
|
2027 | function webViewerWheel(evt) {
|
2028 | const {
|
2029 | pdfViewer,
|
2030 | supportedMouseWheelZoomModifierKeys
|
2031 | } = PDFViewerApplication;
|
2032 |
|
2033 | if (pdfViewer.isInPresentationMode) {
|
2034 | return;
|
2035 | }
|
2036 |
|
2037 | if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
|
2038 | evt.preventDefault();
|
2039 |
|
2040 | if (zoomDisabledTimeout || document.visibilityState === "hidden") {
|
2041 | return;
|
2042 | }
|
2043 |
|
2044 | const previousScale = pdfViewer.currentScale;
|
2045 | const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
|
2046 | const MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
|
2047 | const ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
|
2048 |
|
2049 | if (ticks < 0) {
|
2050 | PDFViewerApplication.zoomOut(-ticks);
|
2051 | } else {
|
2052 | PDFViewerApplication.zoomIn(ticks);
|
2053 | }
|
2054 |
|
2055 | const currentScale = pdfViewer.currentScale;
|
2056 |
|
2057 | if (previousScale !== currentScale) {
|
2058 | const scaleCorrectionFactor = currentScale / previousScale - 1;
|
2059 | const rect = pdfViewer.container.getBoundingClientRect();
|
2060 | const dx = evt.clientX - rect.left;
|
2061 | const dy = evt.clientY - rect.top;
|
2062 | pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
|
2063 | pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
|
2064 | }
|
2065 | } else {
|
2066 | setZoomDisabledTimeout();
|
2067 | }
|
2068 | }
|
2069 |
|
2070 | function webViewerClick(evt) {
|
2071 | if (!PDFViewerApplication.secondaryToolbar.isOpen) {
|
2072 | return;
|
2073 | }
|
2074 |
|
2075 | const appConfig = PDFViewerApplication.appConfig;
|
2076 |
|
2077 | if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
|
2078 | PDFViewerApplication.secondaryToolbar.close();
|
2079 | }
|
2080 | }
|
2081 |
|
2082 | function webViewerKeyDown(evt) {
|
2083 | if (PDFViewerApplication.overlayManager.active) {
|
2084 | return;
|
2085 | }
|
2086 |
|
2087 | let handled = false,
|
2088 | ensureViewerFocused = false;
|
2089 | const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
|
2090 | const pdfViewer = PDFViewerApplication.pdfViewer;
|
2091 | const isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
|
2092 |
|
2093 | if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
|
2094 | switch (evt.keyCode) {
|
2095 | case 70:
|
2096 | if (!PDFViewerApplication.supportsIntegratedFind) {
|
2097 | PDFViewerApplication.findBar.open();
|
2098 | handled = true;
|
2099 | }
|
2100 |
|
2101 | break;
|
2102 |
|
2103 | case 71:
|
2104 | if (!PDFViewerApplication.supportsIntegratedFind) {
|
2105 | const findState = PDFViewerApplication.findController.state;
|
2106 |
|
2107 | if (findState) {
|
2108 | PDFViewerApplication.findController.executeCommand("findagain", {
|
2109 | query: findState.query,
|
2110 | phraseSearch: findState.phraseSearch,
|
2111 | caseSensitive: findState.caseSensitive,
|
2112 | entireWord: findState.entireWord,
|
2113 | highlightAll: findState.highlightAll,
|
2114 | findPrevious: cmd === 5 || cmd === 12
|
2115 | });
|
2116 | }
|
2117 |
|
2118 | handled = true;
|
2119 | }
|
2120 |
|
2121 | break;
|
2122 |
|
2123 | case 61:
|
2124 | case 107:
|
2125 | case 187:
|
2126 | case 171:
|
2127 | if (!isViewerInPresentationMode) {
|
2128 | PDFViewerApplication.zoomIn();
|
2129 | }
|
2130 |
|
2131 | handled = true;
|
2132 | break;
|
2133 |
|
2134 | case 173:
|
2135 | case 109:
|
2136 | case 189:
|
2137 | if (!isViewerInPresentationMode) {
|
2138 | PDFViewerApplication.zoomOut();
|
2139 | }
|
2140 |
|
2141 | handled = true;
|
2142 | break;
|
2143 |
|
2144 | case 48:
|
2145 | case 96:
|
2146 | if (!isViewerInPresentationMode) {
|
2147 | setTimeout(function () {
|
2148 | PDFViewerApplication.zoomReset();
|
2149 | });
|
2150 | handled = false;
|
2151 | }
|
2152 |
|
2153 | break;
|
2154 |
|
2155 | case 38:
|
2156 | if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
|
2157 | PDFViewerApplication.page = 1;
|
2158 | handled = true;
|
2159 | ensureViewerFocused = true;
|
2160 | }
|
2161 |
|
2162 | break;
|
2163 |
|
2164 | case 40:
|
2165 | if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
2166 | PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
2167 | handled = true;
|
2168 | ensureViewerFocused = true;
|
2169 | }
|
2170 |
|
2171 | break;
|
2172 | }
|
2173 | }
|
2174 |
|
2175 | if (cmd === 1 || cmd === 8) {
|
2176 | switch (evt.keyCode) {
|
2177 | case 83:
|
2178 | PDFViewerApplication.download();
|
2179 | handled = true;
|
2180 | break;
|
2181 | }
|
2182 | }
|
2183 |
|
2184 | if (cmd === 3 || cmd === 10) {
|
2185 | switch (evt.keyCode) {
|
2186 | case 80:
|
2187 | PDFViewerApplication.requestPresentationMode();
|
2188 | handled = true;
|
2189 | break;
|
2190 |
|
2191 | case 71:
|
2192 | PDFViewerApplication.appConfig.toolbar.pageNumber.select();
|
2193 | handled = true;
|
2194 | break;
|
2195 | }
|
2196 | }
|
2197 |
|
2198 | if (handled) {
|
2199 | if (ensureViewerFocused && !isViewerInPresentationMode) {
|
2200 | pdfViewer.focus();
|
2201 | }
|
2202 |
|
2203 | evt.preventDefault();
|
2204 | return;
|
2205 | }
|
2206 |
|
2207 | const curElement = document.activeElement || document.querySelector(":focus");
|
2208 | const curElementTagName = curElement && curElement.tagName.toUpperCase();
|
2209 |
|
2210 | if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement && curElement.isContentEditable) {
|
2211 | if (evt.keyCode !== 27) {
|
2212 | return;
|
2213 | }
|
2214 | }
|
2215 |
|
2216 | if (cmd === 0) {
|
2217 | let turnPage = 0,
|
2218 | turnOnlyIfPageFit = false;
|
2219 |
|
2220 | switch (evt.keyCode) {
|
2221 | case 38:
|
2222 | case 33:
|
2223 | if (pdfViewer.isVerticalScrollbarEnabled) {
|
2224 | turnOnlyIfPageFit = true;
|
2225 | }
|
2226 |
|
2227 | turnPage = -1;
|
2228 | break;
|
2229 |
|
2230 | case 8:
|
2231 | if (!isViewerInPresentationMode) {
|
2232 | turnOnlyIfPageFit = true;
|
2233 | }
|
2234 |
|
2235 | turnPage = -1;
|
2236 | break;
|
2237 |
|
2238 | case 37:
|
2239 | if (pdfViewer.isHorizontalScrollbarEnabled) {
|
2240 | turnOnlyIfPageFit = true;
|
2241 | }
|
2242 |
|
2243 | case 75:
|
2244 | case 80:
|
2245 | turnPage = -1;
|
2246 | break;
|
2247 |
|
2248 | case 27:
|
2249 | if (PDFViewerApplication.secondaryToolbar.isOpen) {
|
2250 | PDFViewerApplication.secondaryToolbar.close();
|
2251 | handled = true;
|
2252 | }
|
2253 |
|
2254 | if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
|
2255 | PDFViewerApplication.findBar.close();
|
2256 | handled = true;
|
2257 | }
|
2258 |
|
2259 | break;
|
2260 |
|
2261 | case 40:
|
2262 | case 34:
|
2263 | if (pdfViewer.isVerticalScrollbarEnabled) {
|
2264 | turnOnlyIfPageFit = true;
|
2265 | }
|
2266 |
|
2267 | turnPage = 1;
|
2268 | break;
|
2269 |
|
2270 | case 13:
|
2271 | case 32:
|
2272 | if (!isViewerInPresentationMode) {
|
2273 | turnOnlyIfPageFit = true;
|
2274 | }
|
2275 |
|
2276 | turnPage = 1;
|
2277 | break;
|
2278 |
|
2279 | case 39:
|
2280 | if (pdfViewer.isHorizontalScrollbarEnabled) {
|
2281 | turnOnlyIfPageFit = true;
|
2282 | }
|
2283 |
|
2284 | case 74:
|
2285 | case 78:
|
2286 | turnPage = 1;
|
2287 | break;
|
2288 |
|
2289 | case 36:
|
2290 | if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
|
2291 | PDFViewerApplication.page = 1;
|
2292 | handled = true;
|
2293 | ensureViewerFocused = true;
|
2294 | }
|
2295 |
|
2296 | break;
|
2297 |
|
2298 | case 35:
|
2299 | if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
2300 | PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
2301 | handled = true;
|
2302 | ensureViewerFocused = true;
|
2303 | }
|
2304 |
|
2305 | break;
|
2306 |
|
2307 | case 83:
|
2308 | PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
|
2309 | break;
|
2310 |
|
2311 | case 72:
|
2312 | PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
|
2313 | break;
|
2314 |
|
2315 | case 82:
|
2316 | PDFViewerApplication.rotatePages(90);
|
2317 | break;
|
2318 |
|
2319 | case 115:
|
2320 | PDFViewerApplication.pdfSidebar.toggle();
|
2321 | break;
|
2322 | }
|
2323 |
|
2324 | if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
|
2325 | if (turnPage > 0) {
|
2326 | if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
2327 | PDFViewerApplication.page++;
|
2328 | }
|
2329 | } else {
|
2330 | if (PDFViewerApplication.page > 1) {
|
2331 | PDFViewerApplication.page--;
|
2332 | }
|
2333 | }
|
2334 |
|
2335 | handled = true;
|
2336 | }
|
2337 | }
|
2338 |
|
2339 | if (cmd === 4) {
|
2340 | switch (evt.keyCode) {
|
2341 | case 13:
|
2342 | case 32:
|
2343 | if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
|
2344 | break;
|
2345 | }
|
2346 |
|
2347 | if (PDFViewerApplication.page > 1) {
|
2348 | PDFViewerApplication.page--;
|
2349 | }
|
2350 |
|
2351 | handled = true;
|
2352 | break;
|
2353 |
|
2354 | case 82:
|
2355 | PDFViewerApplication.rotatePages(-90);
|
2356 | break;
|
2357 | }
|
2358 | }
|
2359 |
|
2360 | if (!handled && !isViewerInPresentationMode) {
|
2361 | if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
|
2362 | ensureViewerFocused = true;
|
2363 | }
|
2364 | }
|
2365 |
|
2366 | if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
|
2367 | pdfViewer.focus();
|
2368 | }
|
2369 |
|
2370 | if (handled) {
|
2371 | evt.preventDefault();
|
2372 | }
|
2373 | }
|
2374 |
|
2375 | function apiPageLayoutToSpreadMode(layout) {
|
2376 | switch (layout) {
|
2377 | case "SinglePage":
|
2378 | case "OneColumn":
|
2379 | return _ui_utils.SpreadMode.NONE;
|
2380 |
|
2381 | case "TwoColumnLeft":
|
2382 | case "TwoPageLeft":
|
2383 | return _ui_utils.SpreadMode.ODD;
|
2384 |
|
2385 | case "TwoColumnRight":
|
2386 | case "TwoPageRight":
|
2387 | return _ui_utils.SpreadMode.EVEN;
|
2388 | }
|
2389 |
|
2390 | return _ui_utils.SpreadMode.NONE;
|
2391 | }
|
2392 |
|
2393 | function apiPageModeToSidebarView(mode) {
|
2394 | switch (mode) {
|
2395 | case "UseNone":
|
2396 | return _pdf_sidebar.SidebarView.NONE;
|
2397 |
|
2398 | case "UseThumbs":
|
2399 | return _pdf_sidebar.SidebarView.THUMBS;
|
2400 |
|
2401 | case "UseOutlines":
|
2402 | return _pdf_sidebar.SidebarView.OUTLINE;
|
2403 |
|
2404 | case "UseAttachments":
|
2405 | return _pdf_sidebar.SidebarView.ATTACHMENTS;
|
2406 |
|
2407 | case "UseOC":
|
2408 | }
|
2409 |
|
2410 | return _pdf_sidebar.SidebarView.NONE;
|
2411 | }
|
2412 |
|
2413 | const PDFPrintServiceFactory = {
|
2414 | instance: {
|
2415 | supportsPrinting: false,
|
2416 |
|
2417 | createPrintService() {
|
2418 | throw new Error("Not implemented: createPrintService");
|
2419 | }
|
2420 |
|
2421 | }
|
2422 | };
|
2423 | exports.PDFPrintServiceFactory = PDFPrintServiceFactory; |
\ | No newline at end of file |