UNPKG

ngx-extended-pdf-viewer

Version:

Embedding PDF files in your Angular application. Highly configurable viewer including the toolbar, sidebar, and all the features you're used to.

1,336 lines 307 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ import { Component, ViewEncapsulation, Input, Output, EventEmitter, ChangeDetectionStrategy, HostListener, NgZone, TemplateRef, Inject, PLATFORM_ID, ViewChild, } from '@angular/core'; import { defaultOptions } from './options/default-options'; import { ServiceWorkerOptions } from './options/service-worker-options'; import * as deburr from 'lodash.deburr'; // #177 // #177 import { VerbosityLevel } from './options/verbosity-level'; import { FindState } from './events/find-result'; import { isPlatformBrowser } from '@angular/common'; import { PdfDummyComponentsComponent } from './pdf-dummy-components/pdf-dummy-components.component'; import { ElementRef } from '@angular/core'; import { PdfSecondaryToolbarComponent } from './secondary-toolbar/pdf-secondary-toolbar/pdf-secondary-toolbar.component'; import { PDFNotificationService } from './pdf-notification-service'; import { PdfCursorTools } from './options/pdf-cursor-tools'; import { Location } from '@angular/common'; import { PinchOnMobileSupport } from './pinch-on-mobile-support'; if (typeof window !== 'undefined') { ((/** @type {?} */ (window))).deburr = deburr; // #177 } /** * @record */ function ElementAndPosition() { } if (false) { /** @type {?} */ ElementAndPosition.prototype.element; /** @type {?} */ ElementAndPosition.prototype.x; /** @type {?} */ ElementAndPosition.prototype.y; } var NgxExtendedPdfViewerComponent = /** @class */ (function () { function NgxExtendedPdfViewerComponent(ngZone, platformId, notificationService, location) { this.ngZone = ngZone; this.platformId = platformId; this.notificationService = notificationService; this.location = location; this.customFindbarButtons = undefined; this.srcChange = new EventEmitter(); this.contextMenuAllowed = true; this.afterPrint = new EventEmitter(); this.beforePrint = new EventEmitter(); this.currentZoomFactor = new EventEmitter(); this.enablePrint = true; /** * Number of milliseconds to wait between initializing the PDF viewer and loading the PDF file. * Most users can let this parameter safely at it's default value of zero. * Set this to 1000 or higher if you run into timing problems (typically caused by loading the locale files * after the PDF files, so they are not available when the PDF viewer is initialized). */ this.delayFirstView = 0; /** * How many log messages should be printed? * Legal values: VerbosityLevel.INFOS (= 5), VerbosityLevel.WARNINGS (= 1), VerbosityLevel.ERRORS (= 0) */ this.logLevel = VerbosityLevel.WARNINGS; this.enablePinchOnMobile = false; this.primaryMenuVisible = true; /** * option to increase (or reduce) print resolution. Default is 150 (dpi). Sensible values * are 300, 600, and 1200. Note the increase memory consumption, which may even result in a browser crash. */ this.printResolution = null; this.rotationChange = new EventEmitter(); this.minHeight = undefined; this._height = '100%'; /** * If this flag is true, this components adds a link to the locale assets. The pdf viewer * sees this link and uses it to load the locale files automatically. * @param useBrowserLocale boolean */ this.useBrowserLocale = false; this.backgroundColor = '#e8e8eb'; /** * Allows the user to define the name of the file after clicking "download" */ this.filenameForDownload = 'document.pdf'; /** * Allows the user to disable the keyboard bindings completely */ this.ignoreKeyboard = false; /** * Allows the user to disable a list of key bindings. */ this.ignoreKeys = []; /** * Allows the user to enable a list of key bindings explicitly. If this property is set, every other key binding is ignored. */ this.acceptKeys = []; /** * Allows the user to put the viewer's svg images into an arbitrary folder */ this.imageResourcesPath = './assets/images/'; /** * Override the default locale. This must be the complete locale name, such as "es-ES". The string is allowed to be all lowercase. */ this.language = undefined; /** * By default, listening to the URL is deactivated because often the anchor tag is used for the Angular router */ this.listenToURL = false; /** * Navigate to a certain "named destination" */ this.nameddest = undefined; /** * allows you to pass a password to read password-protected files */ this.password = undefined; this._showSidebarButton = true; this.viewerPositionTop = '32px'; /** * pdf.js can show signatures, but fails to verify them. So they are switched off by default. * Set "[showUnverifiedSignatures]"="true" to display e-signatures nonetheless. */ this.showUnverifiedSignatures = false; /** * If [showSideBarButton]="true", do you want the sidebar to be shown by default ([showSidebarOnLoad])="true") * or not? By default, this flag is undefined, telling the PDF viewer to use the last setting used with this particular * document, or to hide the sidebar if the document is opened for the first time. * @deprecated Use showSidebar instead; dreprecated since 1.8.0; to be removed with 2.0.0 */ this.showSidebarOnLoad = undefined; this.sidebarVisible = undefined; this.sidebarVisibleChange = new EventEmitter(); this.showFindButton = undefined; this.showPagingButtons = true; this.showZoomButtons = true; this.showPresentationModeButton = false; this.showOpenFileButton = true; this.showPrintButton = true; this.showDownloadButton = true; this.showBookmarkButton = true; this.showSecondaryToolbarButton = true; /** * Set by the event (secondaryMenuIsEmpty) */ this.hideKebabMenuForSecondaryToolbar = false; this.showRotateButton = true; this.handTool = true; this.handToolChange = new EventEmitter(); this.showHandToolButton = false; this.showScrollingButton = true; this.showSpreadButton = true; this.showPropertiesButton = true; this.showBorders = false; this.spreadChange = new EventEmitter(); this.page = undefined; this.pageChange = new EventEmitter(); this.pageLabel = undefined; this.pageLabelChange = new EventEmitter(); this.pagesLoaded = new EventEmitter(); this.pageRendered = new EventEmitter(); this.pdfDownloaded = new EventEmitter(); this.pdfLoaded = new EventEmitter(); this.pdfLoadingFailed = new EventEmitter(); this.textLayer = undefined; /** * deprecated */ this.textlayerRendered = new EventEmitter(); this.textLayerRendered = new EventEmitter(); this.updateFindMatchesCount = new EventEmitter(); this.updateFindState = new EventEmitter(); /** * Legal values: undefined, 'auto', 'page-actual', 'page_fit', 'page-width', or '50' (or any other percentage) */ this.zoom = undefined; this.zoomChange = new EventEmitter(); /** * This attributes allows you to increase the size of the UI elements so you can use them on small mobile devices. * This attribute is a string with a percent character at the end (e.g. "150%"). */ this._mobileFriendlyZoom = '100%'; this.mobileFriendlyZoomScale = 1; this.toolbarPaddingTop = '0px'; this.toolbarWidth = '100%'; this.toolbarWidthInPixels = 100; this.secondaryToolbarTop = undefined; // dirty IE11 hack - temporary solution this.findbarTop = undefined; // dirty IE11 hack - temporary solution this.findbarLeft = undefined; this._top = undefined; if (isPlatformBrowser(this.platformId)) { if (!window['pdfjs-dist/build/pdf']) { /** @type {?} */ var isIE = !!((/** @type {?} */ (window))).MSInputMethodContext && !!((/** @type {?} */ (document))).documentMode; /** @type {?} */ var isEdge = /Edge\/\d./i.test(navigator.userAgent); /** @type {?} */ var script = document.createElement('script'); script.src = this.location.normalize(isIE || isEdge ? 'assets/pdf-es5.js' : 'assets/pdf.js'); script.type = 'text/javascript'; script.async = true; document.getElementsByTagName('head')[0].appendChild(script); } if (!((/** @type {?} */ (window))).webViewerLoad) { this.loadViewer(); } } } Object.defineProperty(NgxExtendedPdfViewerComponent.prototype, "src", { set: /** * @param {?} url * @return {?} */ function (url) { if (url instanceof Uint8Array) { this._src = url.buffer; } else if (url instanceof Blob) { this._src = URL.createObjectURL(url); } else if (typeof url === 'string') { this._src = url; if (url.length > 980) { // minimal length of a base64 encoded PDF if (url.length % 4 === 0) { if (/^[a-zA-Z\d\/+]+={0,2}$/.test(url)) { console.error('The URL looks like a base64 encoded string. If so, please use the attribute base64 instead of src'); } } } } else { this._src = url; } }, enumerable: true, configurable: true }); Object.defineProperty(NgxExtendedPdfViewerComponent.prototype, "base64Src", { set: /** * @param {?} base64 * @return {?} */ function (base64) { /** @type {?} */ var binary_string = window.atob(base64); /** @type {?} */ var len = binary_string.length; /** @type {?} */ var bytes = new Uint8Array(len); for (var i = 0; i < len; i++) { bytes[i] = binary_string.charCodeAt(i); } this.src = bytes.buffer; }, enumerable: true, configurable: true }); Object.defineProperty(NgxExtendedPdfViewerComponent.prototype, "height", { get: /** * @return {?} */ function () { return this._height; }, set: /** * @param {?} h * @return {?} */ function (h) { var _this = this; this.minHeight = undefined; if (h) { this._height = h; } else { this.height = '100%'; } setTimeout((/** * @return {?} */ function () { _this.checkHeight(); })); }, enumerable: true, configurable: true }); Object.defineProperty(NgxExtendedPdfViewerComponent.prototype, "showSidebarButton", { get: /** * @return {?} */ function () { return this._showSidebarButton; }, set: /** * @param {?} show * @return {?} */ function (show) { this._showSidebarButton = show; /** @type {?} */ var isIE = /msie\s|trident\//i.test(window.navigator.userAgent); /** @type {?} */ var factor = 1; if (isIE) { factor = Number((this._mobileFriendlyZoom || '100').replace('%', '')) / 100; } if (this._showSidebarButton) { this.findbarLeft = (68 * factor).toString() + 'px'; } else { this.findbarLeft = '0px'; } }, enumerable: true, configurable: true }); Object.defineProperty(NgxExtendedPdfViewerComponent.prototype, "mobileFriendlyZoom", { get: /** * @return {?} */ function () { return this._mobileFriendlyZoom; }, /** * This attributes allows you to increase the size of the UI elements so you can use them on small mobile devices. * This attribute is a string with a percent character at the end (e.g. "150%"). */ set: /** * This attributes allows you to increase the size of the UI elements so you can use them on small mobile devices. * This attribute is a string with a percent character at the end (e.g. "150%"). * @param {?} zoom * @return {?} */ function (zoom) { // tslint:disable-next-line:triple-equals - the type conversion is intended if (zoom == 'true') { zoom = '150%'; // tslint:disable-next-line:triple-equals - the type conversion is intended } else if (zoom == 'false' || zoom === undefined || zoom === null) { zoom = '100%'; } this._mobileFriendlyZoom = zoom; /** @type {?} */ var factor = 1; if (!String(zoom).includes('%')) { zoom = 100 * Number(zoom) + '%'; } factor = Number((zoom || '100').replace('%', '')) / 100; this.mobileFriendlyZoomScale = factor; this.toolbarWidth = (100 / factor).toString() + '%'; this.toolbarPaddingTop = (factor - 1) * 8 + 'px'; if (this.showSidebarButton) { this.findbarLeft = (68 * factor).toString() + 'px'; } else { this.findbarLeft = '0px'; } this.secondaryToolbarTop = (36 + 36 * (factor - 1)).toString() + 'px'; this.findbarTop = (36 + 116 * (factor - 1)).toString() + 'px'; }, enumerable: true, configurable: true }); Object.defineProperty(NgxExtendedPdfViewerComponent.prototype, "mobileZoom", { /** Deprecated. Please use [mobileFriendlyZoom] instead. * This attributes allows you to increase the size of the UI elements so you can use them on small mobile devices. * This attribute is a string with a percent character at the end (e.g. "150%").*/ set: /** * Deprecated. Please use [mobileFriendlyZoom] instead. * This attributes allows you to increase the size of the UI elements so you can use them on small mobile devices. * This attribute is a string with a percent character at the end (e.g. "150%"). * @param {?} mobileFriendlyZoom * @return {?} */ function (mobileFriendlyZoom) { this.mobileFriendlyZoom = mobileFriendlyZoom; }, enumerable: true, configurable: true }); Object.defineProperty(NgxExtendedPdfViewerComponent.prototype, "sidebarPositionTop", { get: /** * @return {?} */ function () { if (this._top) { return this._top; } if (this.mobileFriendlyZoom) { if (this.mobileFriendlyZoom.endsWith('%')) { /** @type {?} */ var zoom = Number(this.mobileFriendlyZoom.substring(0, this.mobileFriendlyZoom.length - 1)); return (2 + 0.29 * zoom).toString() + 'px'; } if (this.mobileFriendlyZoom.endsWith('px')) { return this.mobileFriendlyZoom; } return (16 + 0.16 * Number(this.mobileFriendlyZoom)).toString() + 'px'; } return '32px'; }, enumerable: true, configurable: true }); /** * @return {?} */ NgxExtendedPdfViewerComponent.prototype.calcViewerPositionTop = /** * @return {?} */ function () { if (this._top) { this.viewerPositionTop = this._top; return; } if (this.mobileFriendlyZoom) { if (this.mobileFriendlyZoom.endsWith('%')) { /** @type {?} */ var zoom = Number(this.mobileFriendlyZoom.substring(0, this.mobileFriendlyZoom.length - 1)); if (!this.isPrimaryMenuVisible()) { this.viewerPositionTop = '0'; } else { this.viewerPositionTop = (1 + 0.32 * zoom).toString() + 'px'; } return; } if (this.mobileFriendlyZoom.endsWith('px')) { this.viewerPositionTop = this.mobileFriendlyZoom; return; } } if (this.isPrimaryMenuVisible()) { this.viewerPositionTop = '32px'; } else { this.viewerPositionTop = '0'; } }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.loadViewer = /** * @private * @return {?} */ function () { var _this = this; if (!window['pdfjs-dist/build/pdf']) { setTimeout((/** * @return {?} */ function () { return _this.loadViewer(); }), 25); } else { /** @type {?} */ var isIE = !!((/** @type {?} */ (window))).MSInputMethodContext && !!((/** @type {?} */ (document))).documentMode; /** @type {?} */ var isEdge = /Edge\/\d./i.test(navigator.userAgent); /** @type {?} */ var script2 = document.createElement('script'); script2.src = this.location.normalize(isIE || isEdge ? 'assets/viewer-es5.js' : 'assets/viewer.js'); script2.type = 'text/javascript'; script2.async = true; document.getElementsByTagName('head')[0].appendChild(script2); } }; /** * @param {?} value * @return {?} */ NgxExtendedPdfViewerComponent.prototype.emitZoomChange = /** * @param {?} value * @return {?} */ function (value) { this.zoomChange.emit(value); }; /** * @return {?} */ NgxExtendedPdfViewerComponent.prototype.ngOnInit = /** * @return {?} */ function () { this.onResize(); }; /** * @return {?} */ NgxExtendedPdfViewerComponent.prototype.ngAfterViewInit = /** * @return {?} */ function () { var _this = this; if (((/** @type {?} */ (window))).webViewerLoad) { this.doInitPDFViewer(); } else { setTimeout((/** * @return {?} */ function () { return _this.ngAfterViewInit(); }), 50); } }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.assignTabindexes = /** * @private * @return {?} */ function () { if (this.startTabindex) { /** @type {?} */ var r = (/** @type {?} */ (this.root.nativeElement.cloneNode(true))); r.classList.add('offscreen'); this.showElementsRecursively(r); document.body.appendChild(r); /** @type {?} */ var elements = this.collectElementPositions(r, this.root.nativeElement, []); document.body.removeChild(r); /** @type {?} */ var sorted = elements.sort((/** * @param {?} a * @param {?} b * @return {?} */ function (a, b) { if (a.y - b.y > 15) { return 1; } if (b.y - a.y > 15) { return -1; } return a.x - b.x; })); for (var i = 0; i < sorted.length; i++) { sorted[i].element.tabIndex = this.startTabindex + i; } } }; /** * @private * @param {?} root * @return {?} */ NgxExtendedPdfViewerComponent.prototype.showElementsRecursively = /** * @private * @param {?} root * @return {?} */ function (root) { root.classList.remove('hidden'); root.classList.remove('invisible'); root.classList.remove('hiddenXXLView'); root.classList.remove('hiddenXLView'); root.classList.remove('hiddenLargeView'); root.classList.remove('hiddenMediumView'); root.classList.remove('hiddenSmallView'); root.classList.remove('hiddenTinyView'); root.classList.remove('visibleXXLView'); root.classList.remove('visibleXLView'); root.classList.remove('visibleLargeView'); root.classList.remove('visibleMediumView'); root.classList.remove('visibleSmallView'); root.classList.remove('visibleTinyView'); if (root instanceof HTMLButtonElement || root instanceof HTMLAnchorElement || root instanceof HTMLInputElement || root instanceof HTMLSelectElement) { return; } else if (root.childElementCount > 0) { for (var i = 0; i < root.childElementCount; i++) { /** @type {?} */ var c = root.children.item(i); if (c) { this.showElementsRecursively(c); } } } }; /** * @private * @param {?} copy * @param {?} original * @param {?} elements * @return {?} */ NgxExtendedPdfViewerComponent.prototype.collectElementPositions = /** * @private * @param {?} copy * @param {?} original * @param {?} elements * @return {?} */ function (copy, original, elements) { if (copy instanceof HTMLButtonElement || copy instanceof HTMLAnchorElement || copy instanceof HTMLInputElement || copy instanceof HTMLSelectElement) { /** @type {?} */ var rect = copy.getBoundingClientRect(); /** @type {?} */ var elementAndPos = (/** @type {?} */ ({ element: original, x: Math.round(rect.left), y: Math.round(rect.top), })); elements.push(elementAndPos); } else if (copy.childElementCount > 0) { for (var i = 0; i < copy.childElementCount; i++) { /** @type {?} */ var c = copy.children.item(i); /** @type {?} */ var o = original.children.item(i); if (c && o) { elements = this.collectElementPositions(c, o, elements); } } } return elements; }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.doInitPDFViewer = /** * @private * @return {?} */ function () { var _this = this; /** @type {?} */ var langLinks = document.querySelectorAll('link[type="application/l10n"]'); /** @type {?} */ var langCount = langLinks.length; if (langCount === 0) { /** @type {?} */ var dict = document.querySelector('script[type="application/l10n"]'); if (!dict) { if (!this.useBrowserLocale) { console.error( // tslint:disable-next-line:quotemark "If you set the attribute 'useBrowserLocale' to false, you must provide the translations yourself in a script or link tag."); console.error('The easiest way to do this is to add them to the index.html.'); } } else if (this.useBrowserLocale) { console.error( // tslint:disable-next-line:quotemark "Please set the attribute 'useBrowserLocale' to false if you provide the translations yourself in a script or link tag."); } } else if (this.useBrowserLocale) { /** @type {?} */ var o = langLinks[0].attributes['origin']; if (o && o.value !== 'ngx-extended-pdf-viewer') { console.error( // tslint:disable-next-line:quotemark "Please set the attribute 'useBrowserLocale' to false if you provide the translations yourself in a script or link tag."); } } /** @type {?} */ var callback = (/** * @param {?} e * @return {?} */ function (e) { document.removeEventListener('localized', callback); _this.initTimeout = setTimeout((/** * @return {?} */ function () { _this.afterLibraryInit(); _this.openPDF(); _this.assignTabindexes(); }), _this.delayFirstView); }); window.addEventListener('afterprint', (/** * @param {?} event * @return {?} */ function (event) { _this.afterPrint.emit(); })); window.addEventListener('beforeprint', (/** * @param {?} event * @return {?} */ function (event) { _this.beforePrint.emit(); })); document.addEventListener('localized', callback); if (NgxExtendedPdfViewerComponent.ngxExtendedPdfViewerInitialized) { // tslint:disable-next-line:quotemark console.error("You're trying to open two instances of the PDF viewer. Most likely, this will result in errors."); } /** @type {?} */ var onLoaded = (/** * @return {?} */ function () { _this.overrideDefaultSettings(); document.removeEventListener('webviewerloaded', onLoaded); debugger; if (_this.enablePinchOnMobile) { _this.pinchOnMobileSupport = new PinchOnMobileSupport(_this.ngZone); } }); document.addEventListener('webviewerloaded', onLoaded); this.activateTextlayerIfNecessary(null); setTimeout((/** * @return {?} */ function () { // This initializes the webviewer, the file may be passed in to it to initialize the viewer with a pdf directly _this.primaryMenuVisible = true; /** @type {?} */ var showSecondaryMenu = _this.hideKebabMenuForSecondaryToolbar && _this.showSecondaryToolbarButton; if (showSecondaryMenu) { if (!_this.isPrimaryMenuVisible()) { _this.primaryMenuVisible = false; } } _this.calcViewerPositionTop(); _this.dummyComponents.addMissingStandardWidgets(); ((/** @type {?} */ (window))).webViewerLoad(); /** @type {?} */ var PDFViewerApplication = ((/** @type {?} */ (window))).PDFViewerApplication; PDFViewerApplication.appConfig.defaultUrl = ''; // IE bugfix PDFViewerApplication.appConfig.filenameForDownload = _this.filenameForDownload; /** @type {?} */ var PDFViewerApplicationOptions = ((/** @type {?} */ (window))).PDFViewerApplicationOptions; PDFViewerApplicationOptions.set('locale', _this.language); PDFViewerApplicationOptions.set('imageResourcesPath', _this.imageResourcesPath); PDFViewerApplication.isViewerEmbedded = true; if (PDFViewerApplication.printKeyDownListener) { window.addEventListener('keydown', PDFViewerApplication.printKeyDownListener, true); } /** @type {?} */ var pc = document.getElementById('printContainer'); if (pc) { document.getElementsByTagName('body')[0].appendChild(pc); } }), 0); }; /** Notifies every widget that implements onLibraryInit() that the PDF viewer objects are available */ /** * Notifies every widget that implements onLibraryInit() that the PDF viewer objects are available * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.afterLibraryInit = /** * Notifies every widget that implements onLibraryInit() that the PDF viewer objects are available * @private * @return {?} */ function () { this.notificationService.onPDFJSInit.next(); }; /** * @return {?} */ NgxExtendedPdfViewerComponent.prototype.checkHeight = /** * @return {?} */ function () { /** @type {?} */ var container = document.getElementsByClassName('zoom')[0]; if (container.clientHeight === 0 && this._height.includes('%')) { /** @type {?} */ var available = window.innerHeight; /** @type {?} */ var rect = container.getBoundingClientRect(); /** @type {?} */ var top_1 = rect.top; /** @type {?} */ var mh = available - top_1; /** @type {?} */ var factor = Number(this._height.replace('%', '')); mh = (mh * factor) / 100; if (mh > 100) { this.minHeight = mh + 'px'; } else { this.minHeight = '100px'; } } }; /** * @param {?} newSpread * @return {?} */ NgxExtendedPdfViewerComponent.prototype.onSpreadChange = /** * @param {?} newSpread * @return {?} */ function (newSpread) { this.spreadChange.emit(newSpread); }; /** * @private * @param {?} options * @return {?} */ NgxExtendedPdfViewerComponent.prototype.activateTextlayerIfNecessary = /** * @private * @param {?} options * @return {?} */ function (options) { var _this = this; if (this.textLayer === undefined) { if (!this.handTool) { if (options) { options.set('textLayerMode', 1); } this.textLayer = true; if (this.showFindButton === undefined) { this.showFindButton = true; setTimeout((/** * @return {?} */ function () { // todo remove this hack: /** @type {?} */ var viewFind = (/** @type {?} */ (document.getElementById('viewFind'))); if (viewFind) { viewFind.classList.remove('invisible'); } /** @type {?} */ var findbar = (/** @type {?} */ (document.getElementById('findbar'))); if (findbar) { findbar.classList.remove('invisible'); } })); } } else { if (options) { options.set('textLayerMode', this.showHandToolButton ? 1 : 0); } if (!this.showHandToolButton) { if (this.showFindButton || this.showFindButton === undefined) { this.ngZone.run((/** * @return {?} */ function () { _this.showFindButton = false; })); if (this.logLevel >= VerbosityLevel.WARNINGS) { console.warn( // tslint:disable-next-line:max-line-length 'Hiding the "find" button because the text layer of the PDF file is not rendered. Use [textLayer]="true" to enable the find button.'); } } if (this.showHandToolButton) { if (this.logLevel >= VerbosityLevel.WARNINGS) { console.warn( // tslint:disable-next-line:max-line-length 'Hiding the "hand tool / selection mode" menu because the text layer of the PDF file is not rendered. Use [textLayer]="true" to enable the the menu items.'); this.showHandToolButton = false; } } } } } else { if (this.textLayer) { if (options) { options.set('textLayerMode', 1); } this.textLayer = true; if (this.showFindButton === undefined) { this.showFindButton = true; setTimeout((/** * @return {?} */ function () { // todo remove this hack: /** @type {?} */ var viewFind = (/** @type {?} */ (document.getElementById('viewFind'))); if (viewFind) { viewFind.classList.remove('invisible'); } /** @type {?} */ var findbar = (/** @type {?} */ (document.getElementById('findbar'))); if (findbar) { findbar.classList.remove('invisible'); } })); } } else { if (options) { options.set('textLayerMode', 0); } this.textLayer = false; if (this.showFindButton) { if (this.logLevel >= VerbosityLevel.WARNINGS) { // tslint:disable-next-line:max-line-length console.warn('Hiding the "find" button because the text layer of the PDF file is not rendered. Use [textLayer]="true" to enable the find button.'); this.ngZone.run((/** * @return {?} */ function () { _this.showFindButton = false; })); } } if (this.showHandToolButton) { if (this.logLevel >= VerbosityLevel.WARNINGS) { console.warn( // tslint:disable-next-line:max-line-length 'Hiding the "hand tool / selection mode" menu because the text layer of the PDF file is not rendered. Use [textLayer]="true" to enable the the menu items.'); this.showHandToolButton = false; } } } } }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.overrideDefaultSettings = /** * @private * @return {?} */ function () { /** @type {?} */ var options = (/** @type {?} */ (((/** @type {?} */ (window))).PDFViewerApplicationOptions)); // tslint:disable-next-line:forin for (var key in defaultOptions) { options.set(key, defaultOptions[key]); } options.set('disablePreferences', true); this.setZoom(); options.set('ignoreKeyboard', this.ignoreKeyboard); options.set('ignoreKeys', this.ignoreKeys); options.set('acceptKeys', this.acceptKeys); this.activateTextlayerIfNecessary(options); /** @type {?} */ var sidebarVisible = this.sidebarVisible; if (sidebarVisible === undefined) { sidebarVisible = this.showSidebarOnLoad; } /** @type {?} */ var PDFViewerApplication = ((/** @type {?} */ (window))).PDFViewerApplication; if (sidebarVisible !== undefined) { PDFViewerApplication.sidebarViewOnLoad = sidebarVisible ? 1 : 0; if (PDFViewerApplication.appConfig) { PDFViewerApplication.appConfig.sidebarViewOnLoad = sidebarVisible ? 1 : 0; } options.set('sidebarViewOnLoad', this.sidebarVisible ? 1 : 0); } if (this.spread === 'even') { options.set('spreadModeOnLoad', 2); if (PDFViewerApplication.pdfViewer) { PDFViewerApplication.pdfViewer.spreadMode = 2; } this.onSpreadChange('even'); } else if (this.spread === 'odd') { options.set('spreadModeOnLoad', 1); if (PDFViewerApplication.pdfViewer) { PDFViewerApplication.pdfViewer.spreadMode = 1; } this.onSpreadChange('odd'); } else { options.set('spreadModeOnLoad', 0); if (PDFViewerApplication.pdfViewer) { PDFViewerApplication.pdfViewer.spreadMode = 0; } this.onSpreadChange('off'); } if (this.printResolution) { options.set('printResolution', this.printResolution); } if (this.showBorders) { options.set('showBorders', this.showBorders); } }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.openPDF = /** * @private * @return {?} */ function () { var _this = this; ServiceWorkerOptions.showUnverifiedSignatures = this.showUnverifiedSignatures; /** @type {?} */ var PDFViewerApplication = ((/** @type {?} */ (window))).PDFViewerApplication; PDFViewerApplication.enablePrint = this.enablePrint; NgxExtendedPdfViewerComponent.ngxExtendedPdfViewerInitialized = true; this.onResize(); if (!this.listenToURL) { PDFViewerApplication.pdfLinkService.setHash = (/** * @return {?} */ function () { }); } this.initTimeout = null; this.selectCursorTool(); PDFViewerApplication.eventBus.on('textlayerrendered', (/** * @param {?} x * @return {?} */ function (x) { _this.textlayerRendered.emit(x); // deprecated - kept to avoid a breaking change _this.textLayerRendered.emit(x); })); PDFViewerApplication.eventBus.on('pagesloaded', (/** * @param {?} x * @return {?} */ function (x) { _this.pagesLoaded.emit(x); if (_this.rotation) { /** @type {?} */ var r = Number(_this.rotation); if (r === 0 || r === 90 || r === 180 || r === 270) { PDFViewerApplication.pdfViewer.pagesRotation = r; } } else { PDFViewerApplication.pdfViewer.pagesRotation = 0; } setTimeout((/** * @return {?} */ function () { if (_this.nameddest) { PDFViewerApplication.pdfLinkService.navigateTo(_this.nameddest); } else if (_this.page) { PDFViewerApplication.page = Number(_this.page); } else if (_this.pageLabel) { PDFViewerApplication.pdfViewer.currentPageLabel = _this.pageLabel; } })); _this.setZoom(); })); PDFViewerApplication.eventBus.on('pagerendered', (/** * @param {?} x * @return {?} */ function (x) { _this.ngZone.run((/** * @return {?} */ function () { _this.pageRendered.emit(x); })); })); PDFViewerApplication.eventBus.on('download', (/** * @param {?} x * @return {?} */ function (x) { _this.ngZone.run((/** * @return {?} */ function () { _this.pdfDownloaded.emit(x); })); })); PDFViewerApplication.eventBus.on('scalechanging', (/** * @param {?} x * @return {?} */ function (x) { _this.ngZone.run((/** * @return {?} */ function () { setTimeout((/** * @return {?} */ function () { _this.ngZone.run((/** * @return {?} */ function () { _this.currentZoomFactor.emit(x.scale); if (_this.zoom !== 'auto' && _this.zoom !== 'page-fit' && _this.zoom !== 'page-actual' && _this.zoom !== 'page-width') { _this.emitZoomChange(x.scale * 100); } })); })); })); })); PDFViewerApplication.eventBus.on('rotationchanging', (/** * @param {?} x * @return {?} */ function (x) { _this.ngZone.run((/** * @return {?} */ function () { _this.rotationChange.emit(x.pagesRotation); })); })); PDFViewerApplication.eventBus.on('fileinputchange', (/** * @param {?} x * @return {?} */ function (x) { _this.ngZone.run((/** * @return {?} */ function () { /** @type {?} */ var path = x.fileInput.value.replace('C:\\fakepath\\', ''); _this.srcChange.emit(path); })); })); PDFViewerApplication.eventBus.on('cursortoolchanged', (/** * @param {?} x * @return {?} */ function (x) { _this.ngZone.run((/** * @return {?} */ function () { _this.handToolChange.emit(x.tool === PdfCursorTools.HAND); })); })); PDFViewerApplication.eventBus.on('sidebarviewchanged', (/** * @param {?} x * @return {?} */ function (x) { _this.ngZone.run((/** * @return {?} */ function () { _this.sidebarVisibleChange.emit(x.view === 1); })); })); PDFViewerApplication.eventBus.on('updatefindcontrolstate', (/** * @param {?} x * @return {?} */ function (x) { if (_this.updateFindMatchesCount) { if (x.state === FindState.NOT_FOUND) { _this.updateFindMatchesCount.emit({ current: 0, total: 0 }); } else if (x.matchesCount.total) { _this.updateFindMatchesCount.emit(x.matchesCount); } } if (_this.updateFindState) { _this.updateFindState.emit(x.state); } })); PDFViewerApplication.eventBus.on('updatefindmatchescount', (/** * @param {?} x * @return {?} */ function (x) { if (_this.updateFindMatchesCount) { if (x.matchesCount.total) { _this.updateFindMatchesCount.emit(x.matchesCount); } } })); PDFViewerApplication.eventBus.on('pagechanging', (/** * @param {?} x * @return {?} */ function (x) { _this.ngZone.run((/** * @return {?} */ function () { /** @type {?} */ var currentPage = PDFViewerApplication.pdfViewer.currentPageNumber; /** @type {?} */ var currentPageLabel = PDFViewerApplication.pdfViewer.currentPageLabel; _this.pageChange.emit(currentPage); _this.pageLabelChange.emit(currentPageLabel); })); })); this.checkHeight(); // open a file in the viewer if (!!this._src) { /** @type {?} */ var options = { password: this.password, verbosity: this.logLevel, }; PDFViewerApplication.onError = (/** * @param {?} error * @return {?} */ function (error) { return _this.pdfLoadingFailed.emit(error); }); PDFViewerApplication.open(this._src, options).then((/** * @return {?} */ function () { return _this.pdfLoaded.emit({ pagesCount: PDFViewerApplication.pagesCount }); })); } setTimeout((/** * @return {?} */ function () { if (_this.page) { PDFViewerApplication.page = Number(_this.page); } }), 100); }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.selectCursorTool = /** * @private * @return {?} */ function () { /** @type {?} */ var PDFViewerApplication = ((/** @type {?} */ (window))).PDFViewerApplication; PDFViewerApplication.eventBus.dispatch('switchcursortool', { tool: this.handTool ? 1 : 0 }); }; /** * @return {?} */ NgxExtendedPdfViewerComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { /** @type {?} */ var PDFViewerApplication = ((/** @type {?} */ (window))).PDFViewerApplication; NgxExtendedPdfViewerComponent.ngxExtendedPdfViewerInitialized = false; if (this.initTimeout) { clearTimeout(this.initTimeout); this.initTimeout = undefined; } if (PDFViewerApplication) { if (this.pinchOnMobileSupport) { this.pinchOnMobileSupport.destroyPinchZoom(); this.pinchOnMobileSupport = undefined; } PDFViewerApplication.cleanup(); PDFViewerApplication.close(); if (PDFViewerApplication.printKeyDownListener) { removeEventListener('keydown', PDFViewerApplication.printKeyDownListener, true); } if (PDFViewerApplication._boundEvents) { PDFViewerApplication.unbindWindowEvents(); } /** @type {?} */ var bus = PDFViewerApplication.eventBus; if (bus) { PDFViewerApplication.unbindEvents(); for (var key in bus._listeners) { if (bus._listeners[key]) { /** @type {?} */ var list = bus._listeners[key]; // not sure if the for loop is necessary - but // it might improve garbage collection if the "listeners" // array is stored somewhere else for (var i = 0; i < list.length; i++) { list[i] = undefined; } bus._listeners[key] = undefined; } } } ((/** @type {?} */ (PDFViewerApplication.eventBus))) = null; } /** @type {?} */ var body = document.getElementsByTagName('body'); if (body[0]) { /** @type {?} */ var topLevelElements = body[0].children; for (var i = topLevelElements.length - 1; i >= 0; i--) { /** @type {?} */ var e = topLevelElements.item(i); if (e && e.id === 'printContainer') { body[0].removeChild(e); } else if (e && e.id === 'fileInput') { body[0].removeChild(e); } } } }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.isPrimaryMenuVisible = /** * @private * @return {?} */ function () { /** @type {?} */ var visible = this.showBookmarkButton || this.showDownloadButton || this.showFindButton || this.showOpenFileButton || this.showPagingButtons || this.showPresentationModeButton || this.showPrintButton || this.showPropertiesButton || this.showSidebarButton || this.showZoomButtons; if (visible) { return true; } return false; }; /** * @param {?} changes * @return {?} */ NgxExtendedPdfViewerComponent.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { var _this = this; /** @type {?} */ var PDFViewerApplication = ((/** @type {?} */ (window))).PDFViewerApplication; /** @type {?} */ var PDFViewerApplicationOptions = ((/** @type {?} */ (window))).PDFViewerApplicationOptions; if (NgxExtendedPdfViewerComponent.ngxExtendedPdfViewerInitialized) { if ('src'