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,132 lines (1,122 loc) 304 kB
import * as deburr from 'lodash.deburr'; import { Subject, ReplaySubject } from 'rxjs'; import { FormsModule } from '@angular/forms'; import { Component, Injectable, Renderer2, Inject, Input, ViewEncapsulation, Output, EventEmitter, ChangeDetectionStrategy, HostListener, NgZone, PLATFORM_ID, ViewChild, ElementRef, defineInjectable, NgModule } from '@angular/core'; import { isPlatformBrowser, Location, DOCUMENT, CommonModule, LocationStrategy, PathLocationStrategy } from '@angular/common'; /** * @fileoverview added by tsickle * Generated from: lib/options/default-options.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const _isIE11 = typeof window === 'undefined' ? false : !!((/** @type {?} */ (window))).MSInputMethodContext && !!((/** @type {?} */ (document))).documentMode; /** @type {?} */ const isEdge = /Edge\/\d./i.test(navigator.userAgent); /** @type {?} */ const defaultOptions = { 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: false, sidebarViewOnLoad: -1, scrollModeOnLoad: -1, spreadModeOnLoad: -1, textLayerMode: 1, useOnlyCssZoom: false, viewOnLoad: 0, cMapPacked: true, cMapUrl: '../assets/cmaps/', disableAutoFetch: false, disableCreateObjectURL: false, disableFontFace: false, disableRange: false, disableStream: false, isEvalSupported: true, maxImageSize: -1, pdfBug: false, postMessageTransfers: true, verbosity: 1, workerPort: null, workerSrc: _isIE11 || isEdge ? './assets/pdf.worker-es5.js' : './assets/pdf.worker.js', }; /** * @fileoverview added by tsickle * Generated from: lib/options/service-worker-options.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const ServiceWorkerOptions = { showUnverifiedSignatures: false }; if (typeof window !== 'undefined') { ((/** @type {?} */ (window))).ServiceWorkerOptions = ServiceWorkerOptions; } /** * @fileoverview added by tsickle * Generated from: lib/options/verbosity-level.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ const 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} */ const 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 {?} */ const 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', 'outerContainer', 'viewerContainer', 'sidebarToggle', 'viewThumbnail', 'viewOutline', 'viewAttachments', 'thumbnailView', 'outlineView', 'attachmentsView', 'outerContainer', 'sidebarResizer', 'findbar', 'viewFind', 'findInput', 'findInputMultiline', 'findHighlightAll', 'findMatchCase', 'findEntireWord', 'findMultipleSearchTexts', 'findIgnoreAccents', 'findMsg', 'findResultsCount', 'findPrevious', 'findNext', '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' ]; class PdfDummyComponentsComponent { /** * @return {?} */ addMissingStandardWidgets() { this.dummyComponentsContainer = document.getElementsByClassName('dummy-pdf-viewer-components')[0]; /** @type {?} */ const container = (/** @type {?} */ (this.dummyComponentsContainer)); if (container) { for (let i = 0; i < container.children.length; i++) { /** @type {?} */ const child = container.firstChild; if (child) { container.removeChild(child); } } } requiredIds.forEach((/** * @param {?} id * @return {?} */ id => { if (this.needsDummyWidget(id)) { /** @type {?} */ const dummy = document.createElement('span'); dummy.id = id; dummy.className = 'invisible dummy-component'; this.dummyComponentsContainer.appendChild(dummy); } })); if (this.needsDummyWidget('scaleSelect')) { /** @type {?} */ const dummy = document.createElement('select'); dummy.id = 'scaleSelect'; dummy.className = 'invisible dummy-component'; this.dummyComponentsContainer.appendChild(dummy); } } /** * @private * @param {?} id * @return {?} */ needsDummyWidget(id) { /** @type {?} */ const widget = document.getElementById(id); if (!widget) { return true; } return false; } } PdfDummyComponentsComponent.decorators = [ { type: Component, args: [{ selector: 'pdf-dummy-components', template: "<span class=\"invisible dummy-pdf-viewer-components\">\n</span>\n" }] } ]; /** * @fileoverview added by tsickle * Generated from: lib/pdf-notification-service.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class PDFNotificationService { constructor() { // this event is fired when the pdf.js library has been loaded and objects like PDFApplication are available this.onPDFJSInit = new Subject(); this.pdfjsVersion = new ReplaySubject(1); if (((/** @type {?} */ (window))).pdfjsLib && ((/** @type {?} */ (window))).pdfjsLib.version) { this.pdfjsVersion.next(((/** @type {?} */ (window))).pdfjsLib.version); } else { this.onPDFJSInit.subscribe((/** * @return {?} */ () => { this.pdfjsVersion.next(((/** @type {?} */ (window))).pdfjsLib.version); })); } } } PDFNotificationService.decorators = [ { type: Injectable, args: [{ providedIn: 'root', },] } ]; /** @nocollapse */ PDFNotificationService.ctorParameters = () => []; /** @nocollapse */ PDFNotificationService.ngInjectableDef = defineInjectable({ factory: function PDFNotificationService_Factory() { return new PDFNotificationService(); }, token: PDFNotificationService, providedIn: "root" }); /** * @fileoverview added by tsickle * Generated from: lib/secondary-toolbar/pdf-secondary-toolbar/pdf-secondary-toolbar.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class PdfSecondaryToolbarComponent { /** * @param {?} element * @param {?} notificationService * @param {?} ngZone */ constructor(element, notificationService, ngZone) { this.element = element; this.notificationService = notificationService; this.ngZone = ngZone; this.showPresentationModeButton = true; this.showOpenFileButton = true; this.showPrintButton = true; this.showDownloadButton = true; this.showBookmarkButton = true; this.showPagingButtons = true; this.showRotateButton = true; this.showHandToolButton = true; this.showScrollingButton = true; this.showSpreadButton = true; this.showPropertiesButton = true; this.spreadChange = new EventEmitter(); this.secondaryMenuIsEmpty = new EventEmitter(); this.disablePreviousPage = true; this.disableNextPage = true; /** @type {?} */ const subscription = this.notificationService.onPDFJSInit.subscribe((/** * @return {?} */ () => { this.onPdfJsInit(); subscription.unsubscribe(); })); } /** * @return {?} */ onPdfJsInit() { /** @type {?} */ const PDFViewerApplication = ((/** @type {?} */ (window))).PDFViewerApplication; PDFViewerApplication.eventBus.on('pagechanging', (/** * @return {?} */ () => { this.updateUIState(); })); PDFViewerApplication.eventBus.on('pagerendered', (/** * @return {?} */ () => { this.updateUIState(); })); } /** * @return {?} */ updateUIState() { setTimeout((/** * @return {?} */ () => { /** @type {?} */ const PDFViewerApplication = ((/** @type {?} */ (window))).PDFViewerApplication; /** @type {?} */ const currentPage = PDFViewerApplication.pdfViewer.currentPageNumber; console.log('Upate - current page ' + currentPage + ' pages: ' + PDFViewerApplication.pagesCount); /** @type {?} */ const previousButton = (/** @type {?} */ (document.getElementById('previousPage'))); if (previousButton) { this.disablePreviousPage = Number(currentPage) <= 1; previousButton.disabled = this.disablePreviousPage; console.log('Previous.disabled is ' + this.disablePreviousPage); } /** @type {?} */ const nextButton = (/** @type {?} */ (document.getElementById('previousPage'))); if (nextButton) { this.disableNextPage = currentPage === PDFViewerApplication.pagesCount; nextButton.disabled = this.disableNextPage; } })); } /** * @param {?} newSpread * @return {?} */ onSpreadChange(newSpread) { this.spreadChange.emit(newSpread); } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { setTimeout((/** * @return {?} */ () => this.checkVisibility())); } /** * @return {?} */ onResize() { setTimeout((/** * @return {?} */ () => this.checkVisibility())); } /** * @return {?} */ ngAfterViewInit() { setTimeout((/** * @return {?} */ () => this.checkVisibility())); } /** * @return {?} */ ngOnInit() { setTimeout((/** * @return {?} */ () => this.checkVisibility())); } /** * @return {?} */ checkVisibility() { /** @type {?} */ let visibleButtons = 0; /** @type {?} */ const e = (/** @type {?} */ (this.element.nativeElement)); /** @type {?} */ const f = e.children.item(0); if (f) { /** @type {?} */ const g = f.children.item(0); if (g && g instanceof HTMLElement) { visibleButtons = this.checkVisibilityRecursively(g); } } this.secondaryMenuIsEmpty.emit(visibleButtons === 0); } /** * @private * @param {?} e * @return {?} */ checkVisibilityRecursively(e) { if (e.style.display === 'none') { return 0; } if (e.classList.contains('hidden')) { return 0; } if (e.classList.contains('invisible')) { return 0; } /** @type {?} */ const style = window.getComputedStyle(e); if (style.display === 'none') { return 0; } if (e instanceof HTMLButtonElement || e instanceof HTMLAnchorElement) { return 1; } /** @type {?} */ let count = 0; /** @type {?} */ const children = e.children; if (children && children.length) { for (let i = 0; i < children.length && count === 0; i++) { /** @type {?} */ const child = children.item(i); if (child && child instanceof HTMLElement) { count += this.checkVisibilityRecursively(child); } } } return count; } /** * @return {?} */ previousPage() { /** @type {?} */ const PDFViewerApplication = ((/** @type {?} */ (window))).PDFViewerApplication; PDFViewerApplication.eventBus.dispatch('previouspage'); } /** * @return {?} */ nextPage() { /** @type {?} */ const PDFViewerApplication = ((/** @type {?} */ (window))).PDFViewerApplication; PDFViewerApplication.eventBus.dispatch('nextpage'); } } PdfSecondaryToolbarComponent.decorators = [ { type: Component, args: [{ selector: 'pdf-secondary-toolbar', template: "<ng-container [ngTemplateOutlet]=\"customSecondaryToolbar ? customSecondaryToolbar : defaultSecondaryToolbar\"> </ng-container>\n\n<ng-template #defaultSecondaryToolbar>\n <div\n id=\"secondaryToolbar\"\n class=\"secondaryToolbar hidden doorHangerRight\"\n [style.top]=\"secondaryToolbarTop\"\n [style.transform]=\"'scale(' + mobileFriendlyZoomScale + ')'\"\n [style.transformOrigin]=\"'right top'\"\n >\n <div id=\"secondaryToolbarButtonContainer\">\n <button\n type=\"button\"\n id=\"secondaryPresentationMode\"\n [class.invisible]=\"!showPresentationModeButton\"\n class=\"secondaryToolbarButton visibleLargeView\"\n title=\"Switch to Presentation Mode\"\n data-l10n-id=\"presentation_mode\"\n >\n <svg style=\"width:22px;height:22px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M5,5H10V7H7V10H5V5M14,5H19V10H17V7H14V5M17,14H19V19H14V17H17V14M10,17V19H5V14H7V17H10Z\" />\n </svg>\n <span data-l10n-id=\"presentation_mode_label\">Presentation Mode</span>\n </button>\n\n <button\n type=\"button\"\n id=\"secondaryOpenFile\"\n [class.invisible]=\"!showOpenFileButton\"\n class=\"secondaryToolbarButton visibleMediumView\"\n title=\"Open File\"\n data-l10n-id=\"open_file\"\n >\n <svg style=\"width:22px;height:22px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M14,2L20,8V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2H14M18,20V9H13V4H6V20H18M12,12L16,16H13.5V19H10.5V16H8L12,12Z\" />\n </svg>\n <span data-l10n-id=\"open_file_label\">Open</span>\n </button>\n\n <button\n type=\"button\"\n id=\"secondaryPrint\"\n class=\"secondaryToolbarButton visibleSmallView\"\n [class.invisible]=\"!showPrintButton\"\n title=\"Print\"\n data-l10n-id=\"print\"\n >\n <svg style=\"width:22px;height:22px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M18,3H6V7H18M19,12A1,1 0 0,1 18,11A1,1 0 0,1 19,10A1,1 0 0,1 20,11A1,1 0 0,1 19,12M16,19H8V14H16M19,8H5A3,3 0 0,0 2,11V17H6V21H18V17H22V11A3,3 0 0,0 19,8Z\" />\n </svg>\n <span data-l10n-id=\"print_label\">Print</span>\n </button>\n\n <button\n type=\"button\"\n id=\"secondaryDownload\"\n class=\"secondaryToolbarButton visibleSmallView\"\n [class.invisible]=\"!showDownloadButton\"\n title=\"Download\"\n data-l10n-id=\"download\"\n >\n <svg style=\"width:22px;height:22px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M14,2L20,8V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2H14M18,20V9H13V4H6V20H18M12,19L8,15H10.5V12H13.5V15H16L12,19Z\" />\n </svg>\n <span data-l10n-id=\"download_label\">Download</span>\n </button>\n\n <a\n href=\"#\"\n id=\"secondaryViewBookmark\"\n class=\"secondaryToolbarButton bookmark visibleTinyView\"\n [class.invisible]=\"!showBookmarkButton\"\n title=\"Current view (copy or open in new window)\"\n data-l10n-id=\"bookmark\"\n >\n <svg style=\"width:22px;height:22px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M17,18L12,15.82L7,18V5H17M17,3H7A2,2 0 0,0 5,5V21L12,18L19,21V5C19,3.89 18.1,3 17,3Z\" />\n </svg>\n <span data-l10n-id=\"bookmark_label\">Current View</span>\n </a>\n\n <div class=\"horizontalToolbarSeparator visibleLargeView\"></div>\n\n <button\n type=\"button\"\n [class.invisible]=\"!showPagingButtons\"\n id=\"firstPage\"\n class=\"secondaryToolbarButton firstPage visibleLargeView\"\n title=\"Go to First Page\"\n data-l10n-id=\"first_page\"\n >\n <svg style=\"width:24px;height:24px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M18.41,16.59L13.82,12L18.41,7.41L17,6L11,12L17,18L18.41,16.59M6,6H8V18H6V6Z\" />\n </svg>\n <span data-l10n-id=\"first_page_label\">Go to First Page</span>\n </button>\n <button\n type=\"button\"\n [class.invisible]=\"!showPagingButtons\"\n id=\"previousPage\"\n class=\"secondaryToolbarButton previousPage visibleTinyView\"\n title=\"Go to Previous Page\"\n data-l10n-id=\"previous\"\n (click)=\"previousPage()\"\n >\n <svg style=\"width:24px;height:24px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z\" />\n </svg>\n <span data-l10n-id=\"previous_label\">Go to Previous Page</span>\n </button>\n <button\n type=\"button\"\n [class.invisible]=\"!showPagingButtons\"\n [disabled]=\"disableNextPage\"\n id=\"nextPage\"\n class=\"secondaryToolbarButton nextPage visibleTinyView\"\n title=\"Go to Next Page\"\n data-l10n-id=\"next\"\n (click)=\"nextPage()\"\n >\n <svg style=\"width:24px;height:24px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z\" />\n </svg>\n <span data-l10n-id=\"next_label\">Go to Next Page</span>\n </button>\n <button\n type=\"button\"\n [class.invisible]=\"!showPagingButtons\"\n id=\"lastPage\"\n class=\"secondaryToolbarButton lastPage visibleLargeView\"\n title=\"Go to Last Page\"\n data-l10n-id=\"last_page\"\n >\n <svg style=\"width:24px;height:24px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M5.59,7.41L10.18,12L5.59,16.59L7,18L13,12L7,6L5.59,7.41M16,6H18V18H16V6Z\" />\n </svg>\n <span data-l10n-id=\"last_page_label\">Go to Last Page</span>\n </button>\n\n <div [class.invisible]=\"!showRotateButton\" class=\"horizontalToolbarSeparator visibleXLView\"></div>\n\n <button\n type=\"button\"\n [class.invisible]=\"!showRotateButton\"\n id=\"pageRotateCw\"\n class=\"secondaryToolbarButton rotateCw visibleXLView\"\n title=\"Rotate Clockwise\"\n data-l10n-id=\"page_rotate_cw\"\n >\n <svg style=\"width:22px;height:22px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M12 3C7.03 3 3 7.03 3 12S7.03 21 12 21C14 21 15.92 20.34 17.5 19.14L16.06 17.7C14.87 18.54 13.45 19 12 19C8.13 19 5 15.87 5 12S8.13 5 12 5 19 8.13 19 12H16L20 16L24 12H21C21 7.03 16.97 3 12 3\" />\n </svg>\n <span data-l10n-id=\"page_rotate_cw_label\">Rotate Clockwise</span>\n </button>\n <button\n type=\"button\"\n [class.invisible]=\"!showRotateButton\"\n id=\"pageRotateCcw\"\n class=\"secondaryToolbarButton rotateCcw visibleXLView\"\n title=\"Rotate Counterclockwise\"\n data-l10n-id=\"page_rotate_ccw\"\n >\n <svg style=\"width:22px;height:22px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M12 3C7.03 3 3 7.03 3 12H0L4 16L8 12H5C5 8.13 8.13 5 12 5S19 8.13 19 12 15.87 19 12 19C10.55 19 9.13 18.54 7.94 17.7L6.5 19.14C8.08 20.34 10 21 12 21C16.97 21 21 16.97 21 12S16.97 3 12 3\" />\n </svg>\n <span data-l10n-id=\"page_rotate_ccw_label\">Rotate Counterclockwise</span>\n </button>\n\n <div class=\"horizontalToolbarSeparator visibleXXLView\" [class.invisible]=\"!showHandToolButton\"></div>\n\n <button\n type=\"button\"\n [class.invisible]=\"!showHandToolButton\"\n id=\"cursorSelectTool\"\n class=\"secondaryToolbarButton toggled visibleXXLView\"\n title=\"Enable Text Selection Tool\"\n data-l10n-id=\"cursor_text_select_tool\"\n >\n <svg style=\"width:22px;height:22px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M2 4C2 2.89 2.9 2 4 2H7V4H4V7H2V4M22 4V7H20V4H17V2H20C21.1 2 22 2.89 22 4M2 20V17H4V20H7V22H4C2.9 22 2 21.11 2 20M10 2H14V4H10V2M10 20H14V22H10V20M2 10H4V14H2V10M18.5 13C20.4 13 22 14.6 22 16.5C22 19.1 18.5 23 18.5 23C18.5 23 15 19.1 15 16.5C15 14.6 16.6 13 18.5 13M18.5 17.8C19.2 17.8 19.8 17.2 19.7 16.6C19.7 16 19.1 15.4 18.5 15.4C17.9 15.4 17.3 15.9 17.3 16.6C17.3 17.2 17.8 17.8 18.5 17.8M20 10H22V12.34C21.42 11.84 20.74 11.45 20 11.23V10Z\" />\n </svg>\n <span data-l10n-id=\"cursor_text_select_tool_label\">Text Selection Tool</span>\n </button>\n <button\n type=\"button\"\n [class.invisible]=\"!showHandToolButton\"\n id=\"cursorHandTool\"\n class=\"secondaryToolbarButton visibleXXLView\"\n title=\"Enable Hand Tool\"\n data-l10n-id=\"cursor_hand_tool\"\n >\n <svg style=\"width:22px;height:22px\" viewBox=\"0 0 24 24\">\n <path fill=\"currentColor\" d=\"M13,6V11H18V7.75L22.25,12L18,16.25V13H13V18H16.25L12,22.25L7.75,18H11V13H6V16.25L1.75,12L6,7.75V11H11V6H7.75L12,1.75L16.25,6H13Z\" />\n </svg>\n <span data-l10n-id=\"cursor_hand_tool_label\">Hand Tool</span>\n </button>\n\n <div [class.invisible]=\"!showScrollingButton\" class=\"horizontalToolbarSeparator\"></div>\n\n <button\n type=\"button\"\n [class.invisible]=\"!showScrollingButton\"\n id=\"scrollVertical\"\n class=\"secondaryToolbarButton scrollVertical toggled\"\n title=\"Use Vertical Scrolling\"\n data-l10n-id=\"scroll_vertical\"\n >\n <span data-l10n-id=\"scroll_vertical_label\">Vertical Scrolling</span>\n </button>\n <button\n type=\"button\"\n [class.invisible]=\"!showScrollingButton\"\n id=\"scrollHorizontal\"\n class=\"secondaryToolbarButton scrollHorizontal\"\n title=\"Use Horizontal Scrolling\"\n data-l10n-id=\"scroll_horizontal\"\n >\n <span data-l10n-id=\"scroll_horizontal_label\">Horizontal Scrolling</span>\n </button>\n <button\n type=\"button\"\n [class.invisible]=\"!showScrollingButton\"\n id=\"scrollWrapped\"\n class=\"secondaryToolbarButton scrollWrapped\"\n title=\"Use Wrapped Scrolling\"\n data-l10n-id=\"scroll_wrapped\"\n >\n <span data-l10n-id=\"scroll_wrapped_label\">Wrapped Scrolling</span>\n </button>\n\n <div [class.invisible]=\"!showSpreadButton\" class=\"horizontalToolbarSeparator\"></div>\n\n <button\n type=\"button\"\n [class.invisible]=\"!showSpreadButton\"\n id=\"spreadNone\"\n class=\"secondaryToolbarButton spreadNone toggled\"\n title=\"Do not join page spreads\"\n data-l10n-id=\"spread_none\"\n (click)=\"onSpreadChange('off')\"\n >\n <span data-l10n-id=\"spread_none_label\">No Spreads</span>\n </button>\n <button\n type=\"button\"\n [class.invisible]=\"!showSpreadButton\"\n id=\"spreadOdd\"\n class=\"secondaryToolbarButton spreadOdd\"\n title=\"Join page spreads starting with odd-numbered pages\"\n data-l10n-id=\"spread_odd\"\n (click)=\"onSpreadChange('odd')\"\n >\n <span data-l10n-id=\"spread_odd_label\">Odd Spreads</span>\n </button>\n <button\n type=\"button\"\n [class.invisible]=\"!showSpreadButton\"\n id=\"spreadEven\"\n class=\"secondaryToolbarButton spreadEven\"\n title=\"Join page spreads starting with even-numbered pages\"\n data-l10n-id=\"spread_even\"\n (click)=\"onSpreadChange('even')\"\n >\n <span data-l10n-id=\"spread_even_label\">Even Spreads</span>\n </button>\n\n <div [class.invisible]=\"!showPropertiesButton\" class=\"horizontalToolbarSeparator spreadModeButtons\"></div>\n\n <button\n type=\"button\"\n [class.invisible]=\"!showPropertiesButton\"\n id=\"documentProperties\"\n class=\"secondaryToolbarButton documentProperties\"\n title=\"Document Properties\u2026\"\n data-l10n-id=\"document_properties\"\n >\n <span data-l10n-id=\"document_properties_label\">Document Properties\u2026</span>\n </button>\n </div>\n </div>\n</ng-template>\n", styles: ["svg{position:absolute;display:inline-block;top:0;left:0}"] }] } ]; /** @nocollapse */ PdfSecondaryToolbarComponent.ctorParameters = () => [ { type: ElementRef }, { type: PDFNotificationService }, { type: NgZone } ]; PdfSecondaryToolbarComponent.propDecorators = { customSecondaryToolbar: [{ type: Input }], secondaryToolbarTop: [{ type: Input }], mobileFriendlyZoomScale: [{ type: Input }], showPresentationModeButton: [{ type: Input }], showOpenFileButton: [{ type: Input }], showPrintButton: [{ type: Input }], showDownloadButton: [{ type: Input }], showBookmarkButton: [{ type: Input }], showPagingButtons: [{ type: Input }], showRotateButton: [{ type: Input }], showHandToolButton: [{ type: Input }], showScrollingButton: [{ type: Input }], showSpreadButton: [{ type: Input }], showPropertiesButton: [{ type: Input }], spreadChange: [{ type: Output }], secondaryMenuIsEmpty: [{ type: Output }], onResize: [{ type: HostListener, args: ['window:resize',] }] }; /** * @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} */ const 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 */ class PinchOnMobileSupport { /** * @param {?} _zone */ constructor(_zone) { this._zone = _zone; this.startX = 0; this.startY = 0; this.initialPinchDistance = 0; this.pinchScale = 1; if (this.isMobile()) { this.initializePinchZoom(); } } /** * @private * @return {?} */ isMobile() { return 'ontouchstart' in document.documentElement; } /** * @private * @param {?} event * @return {?} */ onViewerTouchStart(event) { this.initialPinchDistance = 0; if (event.touches.length === 2) { /** @type {?} */ const rect = this.container.getBoundingClientRect(); // + this.container.scrollTop if (event.touches[0].pageX >= rect.left && event.touches[0].pageX <= rect.right) { if (event.touches[0].pageY >= rect.top /* && event.touches[0].pageY <= rect.bottom */) { if (event.touches[1].pageX >= rect.left && event.touches[1].pageX <= rect.right) { if (event.touches[1].pageY >= rect.top /* && event.touches[1].pageY <= rect.bottom */) { 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 {?} */ onViewerTouchMove(event) { if (this.initialPinchDistance <= 0 || event.touches.length !== 2) { return; } if (this.pinchScale !== 1) { event.preventDefault(); } /** @type {?} */ const pinchDistance = Math.hypot(event.touches[1].pageX - event.touches[0].pageX, event.touches[1].pageY - event.touches[0].pageY); /** @type {?} */ const originX = this.startX + this.container.scrollLeft; /** @type {?} */ const originY = this.startY + this.container.scrollTop; this.pinchScale = pinchDistance / this.initialPinchDistance; this.viewer.style.transform = `scale(${this.pinchScale})`; this.viewer.style.transformOrigin = `${originX}px ${originY}px`; event.preventDefault(); event.stopPropagation(); } /** * @private * @param {?} event * @return {?} */ onViewerTouchEnd(event) { /** @type {?} */ const 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 {?} */ const rect = this.container.getBoundingClientRect(); /** @type {?} */ const dx = this.startX - rect.left; /** @type {?} */ const dy = this.startY - rect.top; this.container.scrollLeft += dx * (this.pinchScale - 1); this.container.scrollTop += dy * (this.pinchScale - 1); this.resetPinchZoomParams(); event.preventDefault(); event.stopPropagation(); } /** * @private * @return {?} */ resetPinchZoomParams() { this.startX = this.startY = this.initialPinchDistance = 0; this.pinchScale = 1; } /** * @return {?} */ initializePinchZoom() { this.viewer = document.getElementById('viewer'); this.container = (/** @type {?} */ (document.getElementById('viewerContainer'))); this._zone.runOutsideAngular((/** * @return {?} */ () => { document.addEventListener('touchstart', this.onViewerTouchStart.bind(this)); document.addEventListener('touchmove', this.onViewerTouchMove.bind(this), { passive: false }); document.addEventListener('touchend', this.onViewerTouchEnd.bind(this)); })); } /** * @return {?} */ destroyPinchZoom() { if (this.isMobile()) { document.removeEventListener('touchstart', this.onViewerTouchStart); document.removeEventListener('touchmove', this.onViewerTouchMove); document.removeEventListener('touchend', this.onViewerTouchEnd); } } } /** * @fileoverview added by tsickle * Generated from: lib/ngx-extended-pdf-viewer.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ if (typeof window !== 'undefined') { ((/** @type {?} */ (window))).deburr = deburr; // #177 } class NgxExtendedPdfViewerComponent { /** * @param {?} ngZone * @param {?} platformId * @param {?} notificationService * @param {?} location */ constructor(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 {?} */ const isIE = !!((/** @type {?} */ (window))).MSInputMethodContext && !!((/** @type {?} */ (document))).documentMode; /** @type {?} */ const isEdge = /Edge\/\d./i.test(navigator.userAgent); /** @type {?} */ const 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(); } } } /** * @param {?} url * @return {?} */ set src(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; } } /** * @param {?} base64 * @return {?} */ set base64Src(base64) { /** @type {?} */ const binary_string = window.atob(base64); /** @type {?} */ const len = binary_string.length; /** @type {?} */ const bytes = new Uint8Array(len); for (let i = 0; i < len; i++) { bytes[i] = binary_string.charCodeAt(i); } this.src = bytes.buffer; } /** * @param {?} h * @return {?} */ set height(h) { this.minHeight = undefined; if (h) { this._height = h; } else { this.height = '100%'; } setTimeout((/** * @return {?} */ () => { this.checkHeight(); })); } /** * @return {?} */ get height() { return this._height; } /** * @return {?} */ get showSidebarButton() { return this._showSidebarButton; } /** * @param {?} show * @return {?} */ set showSidebarButton(show) { this._showSidebarButton = show; /** @type {?} */ const isIE = /msie\s|trident\//i.test(window.navigator.userAgent); /** @type {?} */ let factor = 1; if (isIE) { factor = Number((this._mobileFriendlyZoom || '100').replace('%', '')) / 100; } if (this._showSidebarButton) { this.findbarLeft = (68 * factor).toString() + 'px'; } else { this.findbarLeft = '0px'; } } /** * @return {?} */ get page() { return this._page; } /** * @param {?} p * @return {?} */ set page(p) { if (p) { // silently cope with strings this._page = Number(p); } else { this._page = undefined; } } /** * @return {?} */ get mobileFriendlyZoom() { 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%"). * @param {?} zoom * @return {?} */ set mobileFriendlyZoom(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 {?} */ let 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'; } /** * 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 {?} */ set mobileZoom(mobileFriendlyZoom) { this.mobileFriendlyZoom = mobileFriendlyZoom; } /** * @return {?} */ get sidebarPositionTop() { if (this._top) { return this._top; } if (this.mobileFriendlyZoom) { if (this.mobileFriendlyZoom.endsWith('%')) { /** @type {?} */ const 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'; } /** * @return {?} */ calcViewerPositionTop() { if (this._top) { this.viewerPositionTop = this._top; return; } if (this.mobileFriendlyZoom) { if (this.mobileFriendlyZoom.endsWith('%')) { /** @type {?} */ const 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 {?} */ loadViewer() { if (!window['pdfjs-dist/build/pdf']) { setTimeout((/** * @return {?} */ () => this.loadViewer()), 25); } else { /** @type {?} */ const isIE = !!((/** @type {?} */ (window))).MSInputMethodContext && !!((/** @type {?} */ (document))).documentMode; /** @type {?} */ const isEdge = /Edge\/\d./i.test(navigator.userAgent); /** @type {?} */ const 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); } } /** * @return {?} */ ngOnInit() { this.onResize(); } /** * @return {?} */ ngAfterViewInit() { if (((/** @type {?} */ (window))).webViewerLoad) { this.doInitPDFViewer(); } else { setTimeout((/** * @return {?} */ () => this.ngAfterViewInit()), 50); } } /** * @private * @return {?} */ assignTabind