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,212 lines (1,200 loc) 589 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs'), require('@angular/core'), require('@angular/common'), require('@angular/forms')) : typeof define === 'function' && define.amd ? define('ngx-extended-pdf-viewer', ['exports', 'rxjs', '@angular/core', '@angular/common', '@angular/forms'], factory) : (factory((global['ngx-extended-pdf-viewer'] = {}),global.rxjs,global.ng.core,global.ng.common,global.ng.forms)); }(this, (function (exports,rxjs,i0,common,forms) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ var __assign = function () { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } /** * @fileoverview added by tsickle * Generated from: lib/options/pdf-default-options.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var _isIE11 = typeof window === 'undefined' ? false : !!(( /** @type {?} */(window))).MSInputMethodContext && !!(( /** @type {?} */(document))).documentMode; /** @type {?} */ var isEdge = typeof navigator === 'undefined' || /Edge\/\d./i.test(navigator.userAgent); /** @type {?} */ var needsES5 = typeof ReadableStream === 'undefined' || typeof Promise['allSettled'] === 'undefined'; /** @type {?} */ var pdfjsVersion = '2.7.673'; /** @type {?} */ var pdfjsBleedingEdgeVersion = '2.8.230'; /** * @param {?} folder * @return {?} */ function getVersionSuffix(folder) { if (folder && folder.includes('bleeding-edge')) { return pdfjsBleedingEdgeVersion; } return pdfjsVersion; } /** @type {?} */ exports.pdfDefaultOptions = { cursorToolOnLoad: 0, defaultUrl: '', defaultZoomValue: '', disableHistory: false, disablePageLabels: false, enablePrintAutoRotate: false, enableWebGL: false, eventBusDispatchToDOM: false, externalLinkRel: 'noopener noreferrer nofollow', externalLinkTarget: 0, historyUpdateUrl: false, imageResourcesPath: './images/', maxCanvasPixels: 16777216, pdfBugEnabled: false, removePageBorders: false, renderer: 'canvas', renderInteractiveForms: true, sidebarViewOnLoad: -1, scrollModeOnLoad: -1, spreadModeOnLoad: -1, textLayerMode: 1, useOnlyCssZoom: false, viewOnLoad: 0, cMapPacked: true, cMapUrl: ( /** * @return {?} */function () { return './' + exports.pdfDefaultOptions.assetsFolder + '/cmaps/'; }), disableAutoFetch: false, disableCreateObjectURL: false, disableFontFace: false, disableRange: false, disableStream: false, isEvalSupported: true, maxImageSize: -1, pdfBug: false, postMessageTransfers: true, verbosity: 1, workerPort: null, assetsFolder: 'assets', workerSrc: ( /** * @return {?} */function () { return _isIE11 || isEdge || needsES5 ? './' + exports.pdfDefaultOptions.assetsFolder + '/pdf.worker-' + getVersionSuffix(exports.pdfDefaultOptions.assetsFolder) + '-es5.js' : './' + exports.pdfDefaultOptions.assetsFolder + '/pdf.worker-' + getVersionSuffix(exports.pdfDefaultOptions.assetsFolder) + '.js'; }), }; if (typeof window !== 'undefined') { if ((( /** @type {?} */(window))).pdfDefaultOptions) { exports.pdfDefaultOptions = (( /** @type {?} */(window))).pdfDefaultOptions; } else { (( /** @type {?} */(window))).pdfDefaultOptions = exports.pdfDefaultOptions; } } /** * @fileoverview added by tsickle * Generated from: lib/options/verbosity-level.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ var VerbosityLevel = { ERRORS: 0, WARNINGS: 1, INFOS: 5, }; VerbosityLevel[VerbosityLevel.ERRORS] = 'ERRORS'; VerbosityLevel[VerbosityLevel.WARNINGS] = 'WARNINGS'; VerbosityLevel[VerbosityLevel.INFOS] = 'INFOS'; /** * @fileoverview added by tsickle * Generated from: lib/events/find-result.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ var FindState = { FOUND: 0, NOT_FOUND: 1, WRAPPED: 2, PENDING: 3, }; FindState[FindState.FOUND] = 'FOUND'; FindState[FindState.NOT_FOUND] = 'NOT_FOUND'; FindState[FindState.WRAPPED] = 'WRAPPED'; FindState[FindState.PENDING] = 'PENDING'; /** * @fileoverview added by tsickle * Generated from: lib/pdf-dummy-components/pdf-dummy-components.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * List of all field that can be customized * @type {?} */ var requiredIds = [ 'toolbarViewer', 'numPages', 'pageNumber', 'scaleSelectContainer', 'customScaleOption', 'previous', 'next', 'zoomIn', 'zoomOut', 'viewFind', 'openFile', 'print', 'presentationMode', 'download', 'viewBookmark', 'secondaryToolbar', 'secondaryToolbarToggle', 'secondaryToolbarButtonContainer', 'secondaryPresentationMode', 'secondaryOpenFile', 'secondaryPrint', 'secondaryDownload', 'secondaryViewBookmark', 'firstPage', 'lastPage', 'pageRotateCw', 'pageRotateCcw', 'cursorSelectTool', 'cursorHandTool', 'scrollVertical', 'scrollHorizontal', 'scrollWrapped', 'spreadNone', 'spreadOdd', 'spreadEven', 'documentProperties', 'contextFirstPage', 'contextLastPage', 'contextPageRotateCw', 'contextPageRotateCcw', 'currentOutlineItem', 'outerContainer', 'viewerContainer', 'sidebarToggle', 'viewThumbnail', 'viewOutline', 'viewAttachments', 'thumbnailView', 'outlineView', 'attachmentsView', 'outerContainer', 'sidebarResizer', 'findbar', 'viewFind', 'findInput', 'findInputMultiline', 'findHighlightAll', 'findMatchCase', 'findEntireWord', 'findMultipleSearchTexts', 'findIgnoreAccents', 'findMsg', 'findResultsCount', 'findPrevious', 'findNext', 'findFuzzy', 'passwordOverlay', 'passwordText', 'password', 'passwordSubmit', 'passwordCancel', 'documentPropertiesOverlay', 'documentPropertiesClose', 'fileNameField', 'fileSizeField', 'titleField', 'authorField', 'subjectField', 'keywordsField', 'creationDateField', 'modificationDateField', 'creatorField', 'producerField', 'versionField', 'pageCountField', 'pageSizeField', 'linearizedField', 'errorWrapper', 'errorMessage', 'errorClose', 'errorMoreInfo', 'errorShowMore', 'errorShowLess', 'scaleSelectContainer', 'viewAttachments', 'viewLayers', 'viewThumbnail', 'viewOutline', ]; var PdfDummyComponentsComponent = /** @class */ (function () { function PdfDummyComponentsComponent() { } /** * @return {?} */ PdfDummyComponentsComponent.prototype.addMissingStandardWidgets = /** * @return {?} */ function () { var _this = this; this.dummyComponentsContainer = document.getElementsByClassName('dummy-pdf-viewer-components')[0]; /** @type {?} */ var container = ( /** @type {?} */(this.dummyComponentsContainer)); if (container) { for (var i = 0; i < container.children.length; i++) { /** @type {?} */ var child = container.firstChild; if (child) { container.removeChild(child); } } } requiredIds.forEach(( /** * @param {?} id * @return {?} */function (id) { if (_this.needsDummyWidget(id)) { /** @type {?} */ var dummy = document.createElement('span'); dummy.id = id; dummy.className = 'invisible dummy-component'; _this.dummyComponentsContainer.appendChild(dummy); } })); if (this.needsDummyWidget('scaleSelect')) { /** @type {?} */ var dummy = document.createElement('select'); dummy.id = 'scaleSelect'; dummy.className = 'invisible dummy-component'; this.dummyComponentsContainer.appendChild(dummy); } }; /** * @private * @param {?} id * @return {?} */ PdfDummyComponentsComponent.prototype.needsDummyWidget = /** * @private * @param {?} id * @return {?} */ function (id) { /** @type {?} */ var widget = document.getElementById(id); if (!widget) { return true; } return false; }; PdfDummyComponentsComponent.decorators = [ { type: i0.Component, args: [{ selector: 'pdf-dummy-components', template: "<span class=\"invisible dummy-pdf-viewer-components\">\n</span>\n" }] } ]; return PdfDummyComponentsComponent; }()); /** * @fileoverview added by tsickle * Generated from: lib/pdf-notification-service.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var PDFNotificationService = /** @class */ (function () { function PDFNotificationService() { var _this = this; // this event is fired when the pdf.js library has been loaded and objects like PDFApplication are available this.onPDFJSInit = new rxjs.Subject(); this.pdfjsVersion = new rxjs.ReplaySubject(1); if (typeof window !== 'undefined') { if ((( /** @type {?} */(window))).pdfjsLib && (( /** @type {?} */(window))).pdfjsLib.version) { this.pdfjsVersion.next((( /** @type {?} */(window))).pdfjsLib.version); } else { this.onPDFJSInit.subscribe(( /** * @return {?} */function () { _this.pdfjsVersion.next((( /** @type {?} */(window))).pdfjsLib.version); })); } } } PDFNotificationService.decorators = [ { type: i0.Injectable, args: [{ providedIn: 'root', },] } ]; /** @nocollapse */ PDFNotificationService.ctorParameters = function () { return []; }; /** @nocollapse */ PDFNotificationService.ngInjectableDef = i0.defineInjectable({ factory: function PDFNotificationService_Factory() { return new PDFNotificationService(); }, token: PDFNotificationService, providedIn: "root" }); return PDFNotificationService; }()); /** * @fileoverview added by tsickle * Generated from: lib/options/pdf-cursor-tools.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ var PdfCursorTools = { SELECT: 0, HAND: 1, ZOOM: 2, }; PdfCursorTools[PdfCursorTools.SELECT] = 'SELECT'; PdfCursorTools[PdfCursorTools.HAND] = 'HAND'; PdfCursorTools[PdfCursorTools.ZOOM] = 'ZOOM'; /** * @fileoverview added by tsickle * Generated from: lib/pinch-on-mobile-support.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var PinchOnMobileSupport = /** @class */ (function () { function PinchOnMobileSupport(_zone) { this._zone = _zone; this.startX = 0; this.startY = 0; this.initialPinchDistance = 0; this.pinchScale = 1; if (this.isMobile()) { this.initializePinchZoom(); } } /** * @private * @return {?} */ PinchOnMobileSupport.prototype.isMobile = /** * @private * @return {?} */ function () { return 'ontouchstart' in document.documentElement; }; /** * @private * @param {?} event * @return {?} */ PinchOnMobileSupport.prototype.onViewerTouchStart = /** * @private * @param {?} event * @return {?} */ function (event) { this.initialPinchDistance = 0; if (event.touches.length === 2) { /** @type {?} */ var container = ( /** @type {?} */(document.getElementById('viewerContainer'))); /** @type {?} */ var rect = container.getBoundingClientRect(); if (event.touches[0].pageX >= rect.left && event.touches[0].pageX <= rect.right) { if (event.touches[0].pageY >= (rect.top + window.scrollY) && event.touches[0].pageY <= (rect.bottom + window.scrollY)) { if (event.touches[1].pageX >= rect.left && event.touches[1].pageX <= rect.right) { if (event.touches[1].pageY >= (rect.top + window.scrollY) && event.touches[1].pageY <= (rect.bottom + window.scrollY)) { this.startX = (event.touches[0].pageX + event.touches[1].pageX) / 2; this.startY = (event.touches[0].pageY + event.touches[1].pageY) / 2; this.initialPinchDistance = Math.hypot(event.touches[1].pageX - event.touches[0].pageX, event.touches[1].pageY - event.touches[0].pageY); event.preventDefault(); event.stopPropagation(); } } } } } }; /** * @private * @param {?} event * @return {?} */ PinchOnMobileSupport.prototype.onViewerTouchMove = /** * @private * @param {?} event * @return {?} */ function (event) { /** @type {?} */ var PDFViewerApplicationOptions = (( /** @type {?} */(window))).PDFViewerApplicationOptions; /** @type {?} */ var PDFViewerApplication = (( /** @type {?} */(window))).PDFViewerApplication; if (this.initialPinchDistance <= 0 || event.touches.length !== 2) { return; } if (this.pinchScale !== 1) { event.preventDefault(); } /** @type {?} */ var pinchDistance = Math.hypot(event.touches[1].pageX - event.touches[0].pageX, event.touches[1].pageY - event.touches[0].pageY); /** @type {?} */ var container = ( /** @type {?} */(document.getElementById('viewerContainer'))); /** @type {?} */ var originX = this.startX + container.scrollLeft; /** @type {?} */ var originY = this.startY + container.scrollTop; this.pinchScale = pinchDistance / this.initialPinchDistance; /** @type {?} */ var minZoom = Number(PDFViewerApplicationOptions.get('minZoom')); if (!minZoom) { minZoom = 0.1; } /** @type {?} */ var currentZoom = PDFViewerApplication.pdfViewer._currentScale; if (currentZoom * this.pinchScale < minZoom) { this.pinchScale = minZoom / currentZoom; } /** @type {?} */ var maxZoom = Number(PDFViewerApplicationOptions.get('maxZoom')); if (!maxZoom) { maxZoom = 10; } if (currentZoom * this.pinchScale > maxZoom) { this.pinchScale = maxZoom / currentZoom; } this.viewer.style.transform = "scale(" + this.pinchScale + ")"; this.viewer.style.transformOrigin = originX + "px " + originY + "px"; event.preventDefault(); event.stopPropagation(); }; /** * @private * @param {?} event * @return {?} */ PinchOnMobileSupport.prototype.onViewerTouchEnd = /** * @private * @param {?} event * @return {?} */ function (event) { /** @type {?} */ var PDFViewerApplication = (( /** @type {?} */(window))).PDFViewerApplication; if (this.initialPinchDistance <= 0) { return; } this.viewer.style.transform = "none"; this.viewer.style.transformOrigin = "unset"; PDFViewerApplication.pdfViewer.currentScale *= this.pinchScale; /** @type {?} */ var container = ( /** @type {?} */(document.getElementById('viewerContainer'))); /** @type {?} */ var rect = container.getBoundingClientRect(); /** @type {?} */ var dx = this.startX - rect.left; /** @type {?} */ var dy = this.startY - rect.top; container.scrollLeft += dx * (this.pinchScale - 1); container.scrollTop += dy * (this.pinchScale - 1); this.resetPinchZoomParams(); event.preventDefault(); event.stopPropagation(); }; /** * @private * @return {?} */ PinchOnMobileSupport.prototype.resetPinchZoomParams = /** * @private * @return {?} */ function () { this.startX = this.startY = this.initialPinchDistance = 0; this.pinchScale = 1; }; /** * @return {?} */ PinchOnMobileSupport.prototype.initializePinchZoom = /** * @return {?} */ function () { var _this = this; this.viewer = document.getElementById('viewer'); this._zone.runOutsideAngular(( /** * @return {?} */function () { document.addEventListener('touchstart', _this.onViewerTouchStart.bind(_this)); document.addEventListener('touchmove', _this.onViewerTouchMove.bind(_this), { passive: false }); document.addEventListener('touchend', _this.onViewerTouchEnd.bind(_this)); })); }; /** * @return {?} */ PinchOnMobileSupport.prototype.destroyPinchZoom = /** * @return {?} */ function () { if (this.isMobile()) { document.removeEventListener('touchstart', this.onViewerTouchStart); document.removeEventListener('touchmove', this.onViewerTouchMove); document.removeEventListener('touchend', this.onViewerTouchEnd); } }; return PinchOnMobileSupport; }()); /** * @fileoverview added by tsickle * Generated from: lib/options/pdf-viewer.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ var ScrollModeType = { vertical: 0, horizontal: 1, wrapped: 2, }; ScrollModeType[ScrollModeType.vertical] = 'vertical'; ScrollModeType[ScrollModeType.horizontal] = 'horizontal'; ScrollModeType[ScrollModeType.wrapped] = 'wrapped'; /** * @fileoverview added by tsickle * Generated from: lib/ngx-extended-pdf-viewer.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxExtendedPdfViewerComponent = /** @class */ (function () { function NgxExtendedPdfViewerComponent(ngZone, platformId, notificationService, location, elementRef) { this.ngZone = ngZone; this.platformId = platformId; this.notificationService = notificationService; this.location = location; this.elementRef = elementRef; this.customFindbarButtons = undefined; this.formData = {}; this.formDataChange = new i0.EventEmitter(); this.pageViewMode = 'multiple'; this.progress = new i0.EventEmitter(); this.srcChange = new i0.EventEmitter(); this.scrollMode = undefined; this.scrollModeChange = new i0.EventEmitter(); this.authorization = undefined; this.httpHeaders = undefined; this.contextMenuAllowed = true; this.afterPrint = new i0.EventEmitter(); this.beforePrint = new i0.EventEmitter(); this.currentZoomFactor = new i0.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; /** * Use the minified (minifiedJSLibraries="true", which is the default) or the user-readable pdf.js library (minifiedJSLibraries="false") */ this.minifiedJSLibraries = true; 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 i0.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 = './' + exports.pdfDefaultOptions.assetsFolder + '/images/'; /** * Allows the user to put their locale folder into an arbitrary folder */ this.localeFolderPath = './' + exports.pdfDefaultOptions.assetsFolder + '/locale'; /** * 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; this.sidebarVisible = undefined; this.sidebarVisibleChange = new i0.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.theme = 'light'; this.showToolbar = true; this.showSecondaryToolbarButton = true; /** * Set by the event (secondaryMenuIsEmpty) */ this.hideKebabMenuForSecondaryToolbar = false; this.showRotateButton = true; this.handTool = true; this.handToolChange = new i0.EventEmitter(); this.showHandToolButton = false; this.showScrollingButton = true; this.showSpreadButton = true; this.showPropertiesButton = true; this.showBorders = true; this.spreadChange = new i0.EventEmitter(); this.thumbnailDrawn = new i0.EventEmitter(); this._page = undefined; this.pageChange = new i0.EventEmitter(); this.pageLabel = undefined; this.pageLabelChange = new i0.EventEmitter(); this.pagesLoaded = new i0.EventEmitter(); this.pageRendered = new i0.EventEmitter(); this.pdfDownloaded = new i0.EventEmitter(); this.pdfLoaded = new i0.EventEmitter(); this.pdfLoadingFailed = new i0.EventEmitter(); this.textLayer = undefined; this.textLayerRendered = new i0.EventEmitter(); this.updateFindMatchesCount = new i0.EventEmitter(); this.updateFindState = new i0.EventEmitter(); /** * Legal values: undefined, 'auto', 'page-actual', 'page_fit', 'page-width', or '50' (or any other percentage) */ this.zoom = undefined; this.zoomChange = new i0.EventEmitter(); this.zoomLevels = ['auto', 'page-actual', 'page-fit', 'page-width', 0.5, 1, 1.25, 1.5, 2, 3, 4]; this.maxZoom = 10; this.minZoom = 0.1; /** * This attribute 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.toolbarMarginTop = '0px'; this.toolbarWidth = '100%'; this.toolbarWidthInPixels = 100; this.secondaryToolbarTop = undefined; this.sidebarPositionTop = undefined; // dirty IE11 hack - temporary solution this.findbarTop = undefined; // dirty IE11 hack - temporary solution this.findbarLeft = undefined; // Additional PDF Form Field Types #567: Used to store the exported values of radio and checkbox buttons this.buttonValues = {}; this.shuttingDown = false; } Object.defineProperty(NgxExtendedPdfViewerComponent.prototype, "src", { set: /** * @param {?} url * @return {?} */ function (url) { var _this = this; if (url instanceof Uint8Array) { this._src = url.buffer; } else if (typeof Blob !== 'undefined' && url instanceof Blob) { // additional check introduced to support server side rendering // additional check introduced to support server side rendering /** @type {?} */ var reader_1 = new FileReader(); reader_1.onloadend = ( /** * @return {?} */function () { setTimeout(( /** * @return {?} */function () { _this.src = new Uint8Array(( /** @type {?} */(reader_1.result))); if (NgxExtendedPdfViewerComponent.ngxExtendedPdfViewerInitialized) { _this.openPDF2(); // else openPDF is called later, so we should load the PDF file twice } })); }); reader_1.readAsArrayBuffer(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 [base64Src] instead of [src]'); } } } } else { (( /** @type {?} */(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, "page", { get: /** * @return {?} */ function () { return this._page; }, set: /** * @param {?} p * @return {?} */ function (p) { if (p) { // silently cope with strings this._page = Number(p); } else { this._page = undefined; } }, 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) { var _this = this; // 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.toolbarMarginTop = (factor - 1) * 16 + 'px'; setTimeout(( /** * @return {?} */function () { return _this.calcViewerPositionTop(); })); }, enumerable: true, configurable: true }); /** * @return {?} */ NgxExtendedPdfViewerComponent.prototype.calcViewerPositionTop = /** * @return {?} */ function () { /** @type {?} */ var toolbar = ( /** @type {?} */(document.getElementsByClassName("toolbar")[0])); /** @type {?} */ var top = toolbar.getBoundingClientRect().height; this.viewerPositionTop = top + "px"; /** @type {?} */ var factor = top / 33; this.sidebarPositionTop = (33 + 33 * (factor - 1)).toString() + 'px'; this.secondaryToolbarTop = (33 + 38 * (factor - 1)).toString() + 'px'; this.findbarTop = (34 + 54 * (factor - 1)).toString() + 'px'; /** @type {?} */ var findButton = document.getElementById("viewFind"); if (findButton) { /** @type {?} */ var containerPositionLeft = toolbar.getBoundingClientRect().left; /** @type {?} */ var findButtonPosition = findButton.getBoundingClientRect(); /** @type {?} */ var left = findButtonPosition.left - containerPositionLeft; this.findbarLeft = left + "px"; } else if (this.showSidebarButton) { this.findbarLeft = 34 + (32 * factor).toString() + 'px'; } else { this.findbarLeft = '0px'; } }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.iOSVersionRequiresES5 = /** * @private * @return {?} */ function () { /** @type {?} */ var match = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/); if (match !== undefined && match !== null) { return parseInt(match[1], 10) < 14; } return false; }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.needsES5 = /** * @private * @return {?} */ function () { /** @type {?} */ var isIE = !!(( /** @type {?} */(window))).MSInputMethodContext && !!(( /** @type {?} */(document))).documentMode; /** @type {?} */ var isEdge = /Edge\/\d./i.test(navigator.userAgent); /** @type {?} */ var isIOs13OrBelow = this.iOSVersionRequiresES5(); /** @type {?} */ var needsES5 = typeof ReadableStream === 'undefined' || typeof Promise['allSettled'] === 'undefined'; needsES5 = needsES5 || !ngxBrowserSupportsNullSafeChaining(); needsES5 = needsES5 || isIE || isEdge || isIOs13OrBelow; return needsES5; }; /** * @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 needsES5 = this.needsES5(); /** @type {?} */ var suffix = this.minifiedJSLibraries ? '.min.js' : '.js'; /** @type {?} */ var script2 = document.createElement('script'); /** @type {?} */ var assets = exports.pdfDefaultOptions.assetsFolder; /** @type {?} */ var versionSuffix = getVersionSuffix(assets); if (needsES5) { console.log('Using the ES5 version of the PDF viewer.'); } script2.src = this.location.normalize(needsES5 ? assets + '/viewer-' + versionSuffix + '-es5' + suffix : assets + '/viewer-' + versionSuffix + suffix); script2.type = 'text/javascript'; script2.async = true; document.getElementsByTagName('head')[0].appendChild(script2); } }; /** * @return {?} */ NgxExtendedPdfViewerComponent.prototype.ngOnInit = /** * @return {?} */ function () { if (common.isPlatformBrowser(this.platformId)) { /** @type {?} */ var link = document.createElement('link'); link.href = this.localeFolderPath + '/locale.properties'; link.setAttribute('origin', 'ngx-extended-pdf-viewer'); link.rel = 'resource'; link.type = 'application/l10n'; /** @type {?} */ var widget = this.elementRef.nativeElement; widget.appendChild(link); this.onResize(); this.checkBrowserCompatibilityAndLoadPdsjs(); } }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.checkBrowserCompatibilityAndLoadPdsjs = /** * @private * @return {?} */ function () { var _this = this; if (!window["ngxBrowserSupportsNullSafeChaining"]) { /** @type {?} */ var assets = exports.pdfDefaultOptions.assetsFolder; /** @type {?} */ var script = document.createElement('script'); script.src = this.location.normalize(assets + "/ngx-compatibility-checks.js"); script.type = 'text/javascript'; script.async = false; script.onload = ( /** * @return {?} */function () { return _this.loadPdfJs(); }); document.getElementsByTagName('head')[0].appendChild(script); } else { this.loadPdfJs(); } }; /** * @private * @return {?} */ NgxExtendedPdfViewerComponent.prototype.loadPdfJs = /** * @private * @return {?} */ function () { if (!window['pdfjs-dist/build/pdf']) { /** @type {?} */ var needsES5 = this.needsES5(); /** @type {?} */ var suffix = this.minifiedJSLibraries ? '.min.js' : '.js'; if (this.minifiedJSLibraries) { if (!exports.pdfDefaultOptions.workerSrc().endsWith('.min.js