(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common/http')) : typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/common/http'], factory) : (factory((global['simple-pdf-viewer'] = {}),global.ng.core,global.ng.common.http)); }(this, (function (exports,core,http) { 'use strict'; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** @enum {number} */ var SimpleSearchState = { FOUND: 0, NOT_FOUND: 1, WRAPPED: 2, PENDING: 3, }; SimpleSearchState[SimpleSearchState.FOUND] = "FOUND"; SimpleSearchState[SimpleSearchState.NOT_FOUND] = "NOT_FOUND"; SimpleSearchState[SimpleSearchState.WRAPPED] = "WRAPPED"; SimpleSearchState[SimpleSearchState.PENDING] = "PENDING"; /** * PDF Document basic information representation */ var SimpleDocumentInfo = /** @class */ (function () { /** * @param {?} key * @param {?} value */ function SimpleDocumentInfo(key, value) { this.key = key; this.value = value; } return SimpleDocumentInfo; }()); /** * Representation of the Outline nodes */ var SimpleOutlineNode = /** @class */ (function () { /** * @param {?} title * @param {?} dest * @param {?} items */ function SimpleOutlineNode(title, dest, items) { this.title = title; this.dest = dest; this.items = items; } return SimpleOutlineNode; }()); /** * Representation of the loading progress */ var SimpleProgressData = /** @class */ (function () { /** * @param {?} loaded * @param {?} total */ function SimpleProgressData(loaded, total) { this.loaded = loaded; this.total = total; } return SimpleProgressData; }()); /** * Representation of the settings of the search */ var SimpleSearchOptions = /** @class */ (function () { /** * @param {?=} caseSensitive * @param {?=} highlightAll * @param {?=} phraseSearch */ function SimpleSearchOptions(caseSensitive, highlightAll, phraseSearch) { if (caseSensitive === void 0) { caseSensitive = false; } if (highlightAll === void 0) { highlightAll = true; } if (phraseSearch === void 0) { phraseSearch = true; } this.caseSensitive = caseSensitive; this.highlightAll = highlightAll; this.phraseSearch = phraseSearch; } return SimpleSearchOptions; }()); SimpleSearchOptions.DEFAULT_OPTIONS = new SimpleSearchOptions(); /** * Representation of the PDF bookmark */ var SimplePDFBookmark = /** @class */ (function () { /** * @param {?=} page * @param {?=} zoom * @param {?=} rotation * @param {?=} x * @param {?=} y */ function SimplePDFBookmark(page, zoom, rotation, x, y) { if (page === void 0) { page = 1; } if (zoom === void 0) { zoom = 1; } if (rotation === void 0) { rotation = 0; } if (x === void 0) { x = 0; } if (y === void 0) { y = 0; } this.page = page; this.zoom = zoom; this.rotation = rotation; this.x = x; this.y = y; } /** * Build destination object to navigation * @return {?} */ SimplePDFBookmark.prototype.toDestination = function () { return { pageNumber: this.page, destArray: [null, { name: 'XYZ' }, this.x, this.y, this.zoom] }; }; /** * Build query string to URL * @return {?} */ SimplePDFBookmark.prototype.toQueryString = function () { return "" + SimplePDFBookmark.PARAMETER_SEPARATOR + (SimplePDFBookmark.PARAMETER_PAGE + "=" + this.page + SimplePDFBookmark.PARAMETER_SEPARATOR) + (SimplePDFBookmark.PARAMETER_ZOOM + "=" + this.zoom + SimplePDFBookmark.PARAMETER_SEPARATOR) + (SimplePDFBookmark.PARAMETER_ROTATION + "=" + this.rotation + SimplePDFBookmark.PARAMETER_SEPARATOR) + (SimplePDFBookmark.PARAMETER_X + "=" + this.x + SimplePDFBookmark.PARAMETER_SEPARATOR) + (SimplePDFBookmark.PARAMETER_Y + "=" + this.y); }; /** * Build bookmark obeject from src url * @param {?} src * @return {?} */ SimplePDFBookmark.buildSimplePDFBookmark = function (src) { if (src && typeof src === 'string' && src.trim().length > 0) { var /** @type {?} */ parts = src.split(SimplePDFBookmark.PARAMETER_SEPARATOR); if (parts.length > 0) { var /** @type {?} */ bookmark_1 = new SimplePDFBookmark(); parts.forEach(function (part) { var /** @type {?} */ parameters = part.split("="); var /** @type {?} */ paramert_name = parameters[0]; if (parameters.length === 2 && bookmark_1.hasOwnProperty(paramert_name)) { var /** @type {?} */ paramert_value = 0; if (paramert_name === SimplePDFBookmark.PARAMETER_ZOOM) { paramert_value = parseFloat("" + parameters[1]); } else { paramert_value = parseInt("" + parameters[1], 10); } paramert_value = Number.isNaN(paramert_value) ? 0 : paramert_value; bookmark_1[paramert_name] = paramert_value; } }); return bookmark_1; } } return SimplePDFBookmark.EMPTY_BOOKMARK; }; return SimplePDFBookmark; }()); SimplePDFBookmark.EMPTY_BOOKMARK = new SimplePDFBookmark(1, 0.75, 0, 0, 0); SimplePDFBookmark.PARAMETER_SEPARATOR = '#'; SimplePDFBookmark.PARAMETER_PAGE = 'page'; SimplePDFBookmark.PARAMETER_ZOOM = 'zoom'; SimplePDFBookmark.PARAMETER_ROTATION = 'rotation'; SimplePDFBookmark.PARAMETER_X = 'x'; SimplePDFBookmark.PARAMETER_Y = 'y'; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** @enum {number} */ var ScalePriority = { FULL: 0, WIDTH: 1, HEIGHT: 2, }; ScalePriority[ScalePriority.FULL] = "FULL"; ScalePriority[ScalePriority.WIDTH] = "WIDTH"; ScalePriority[ScalePriority.HEIGHT] = "HEIGHT"; if (typeof window !== 'undefined') { window['pdfjs-dist/build/pdf'] = require('pdfjs-dist/build/pdf'); require('pdfjs-dist/web/compatibility'); require('pdfjs-dist/web/pdf_viewer'); PDFJS.verbosity = ((PDFJS)).VERBOSITY_LEVELS.errors; } /** * Simple PDF Viewer component */ var SimplePdfViewerComponent = /** @class */ (function () { /** * @param {?} element * @param {?} http */ function SimplePdfViewerComponent(element, http$$1) { this.element = element; this.http = http$$1; /** * Page border is displayed or not (Optional) */ this.removePageBorders = false; /** * Text layer is displayed or not (Optional) */ this.disableTextLayer = false; this.onLoadComplete = new core.EventEmitter(); this.onError = new core.EventEmitter(); this.onProgress = new core.EventEmitter(); this.onSearchStateChange = new core.EventEmitter(); this.startAt = SimplePDFBookmark.EMPTY_BOOKMARK; this.loaded = false; this.currentPage = 1; this.numberOfPages = 1; this.outline = []; this.zoom = 1.0; this.rotation = 0; this.searching = false; this.lastSearchText = ''; this.searchPrevious = false; this.searchOptions = SimpleSearchOptions.DEFAULT_OPTIONS; } /** * @return {?} */ SimplePdfViewerComponent.prototype.ngOnInit = function () { if (typeof window !== 'undefined') { if (typeof PDFJS.workerSrc !== 'string') { var /** @type {?} */ workerUrl = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/" + (((PDFJS))).version + "/pdf.worker.min.js"; PDFJS.workerSrc = workerUrl; } this.initPDFJS(); this.openDocument(this.src); } }; /** * @return {?} */ SimplePdfViewerComponent.prototype.ngOnDestroy = function () { if (this.pdf) { this.pdf.destroy(); } }; /** * Open a PDF document at the specified page (at the first page by default) * @param {?} src Source of the PDF document * @param {?=} startAt The bookmark where should start, default: at the first page * @return {?} */ SimplePdfViewerComponent.prototype.openDocument = function (src, startAt) { if (startAt === void 0) { startAt = SimplePDFBookmark.EMPTY_BOOKMARK; } this.resetParameters(); this.startAt = startAt; this.setAndParseSrc(src); this.loadFile(); }; /** * Open a PDF document at the specified page (at the first page by default) * @param {?} file The File source of the PDF document * @param {?=} startAt The bookmark where should start, default: at the first page * @return {?} */ SimplePdfViewerComponent.prototype.openFile = function (file, startAt) { var _this = this; if (startAt === void 0) { startAt = SimplePDFBookmark.EMPTY_BOOKMARK; } try { var /** @type {?} */ fileReader_1 = new FileReader(); fileReader_1.onload = function () { _this.openDocument(new Uint8Array(fileReader_1.result), startAt); }; fileReader_1.onerror = function (error) { _this.onError.emit(error); _this.loaded = false; }; fileReader_1.readAsArrayBuffer(file); } catch (error) { this.onError.emit(error); this.loaded = false; } }; /** * Open a PDF document at the specified page (at the first page by default) * @param {?} url The url of the PDF document * @param {?=} startAt The bookmark where should start, default: at the first page * @return {?} */ SimplePdfViewerComponent.prototype.openUrl = function (url, startAt) { var _this = this; if (startAt === void 0) { startAt = SimplePDFBookmark.EMPTY_BOOKMARK; } this.http.get(url, { responseType: 'arraybuffer' }) .subscribe(function (file) { _this.openDocument(new Uint8Array(file), startAt); }, function (error) { _this.onError.emit(error); _this.loaded = false; }); }; /** * Returns whether the PDF document is loaded properly * @return {?} */ SimplePdfViewerComponent.prototype.isDocumentLoaded = function () { return this.loaded; }; /** * @return {?} */ SimplePdfViewerComponent.prototype.initPDFJS = function () { var /** @type {?} */ container = this.getContainer(); ((PDFJS)).disableTextLayer = this.disableTextLayer; this.pdfLinkService = new ((PDFJS)).PDFLinkService(); this.pdfViewer = new ((PDFJS)).PDFSinglePageViewer({ container: container, removePageBorders: this.removePageBorders, linkService: this.pdfLinkService, }); this.pdfLinkService.setViewer(this.pdfViewer); this.pdfFindController = new ((PDFJS)).PDFFindController({ pdfViewer: this.pdfViewer }); this.pdfViewer.setFindController(this.pdfFindController); container.addEventListener('pagesinit', this.pagesinitEventListener.bind(this)); container.addEventListener('pagechange', this.pagechangeEventListener.bind(this)); container.addEventListener('updateviewarea', this.updateviewareaEventListener.bind(this)); }; /** * @return {?} */ SimplePdfViewerComponent.prototype.pagesinitEventListener = function () { this.pdfViewer.currentScaleValue = SimplePdfViewerComponent.PDF_VIEWER_DEFAULT_SCALE; this.navigateToBookmark(this.startAt); this.onLoadComplete.emit(); }; /** * @return {?} */ SimplePdfViewerComponent.prototype.pagechangeEventListener = function () { this.currentPage = this.pdfViewer._currentPageNumber; }; /** * @return {?} */ SimplePdfViewerComponent.prototype.updateviewareaEventListener = function () { this.zoom = this.pdfViewer._currentScale; }; /** * @param {?} src * @return {?} */ SimplePdfViewerComponent.prototype.setAndParseSrc = function (src) { this.src = src; if (this.src && typeof this.src === 'string') { var /** @type {?} */ parts = this.src.split(SimplePDFBookmark.PARAMETER_SEPARATOR); if (parts.length > 1) { this.startAt = SimplePDFBookmark.buildSimplePDFBookmark(this.src); this.src = parts[0]; } } }; /** * @return {?} */ SimplePdfViewerComponent.prototype.loadFile = function () { var _this = this; this.loaded = false; if (this.src) { if (this.pdf) { this.pdf.destroy(); } var /** @type {?} */ progressSrc = void 0; if (typeof this.src === 'string') { progressSrc = PDFJS.getDocument(/** @type {?} */ ({ url: this.src, withCredentials: true })); } else { progressSrc = PDFJS.getDocument(/** @type {?} */ (this.src)); } // progress progressSrc.onProgress = function (progressData) { _this.onProgress.emit(new SimpleProgressData(progressData.loaded, progressData.total)); }; // loaded ((progressSrc.promise)).then(function (pdfDocument) { _this.pdfViewer.setDocument(pdfDocument); _this.pdfViewer.currentScaleValue = SimplePdfViewerComponent.PDF_VIEWER_DEFAULT_SCALE; _this.pdfLinkService.setDocument(pdfDocument, null); _this.pdf = pdfDocument; _this.pdf.getOutline().then(function (nodes) { _this.outline = _this.mapOutline(nodes); }); _this.pdf.getMetadata().then(function (information) { Object.getOwnPropertyNames(information.info).forEach(function (key) { _this.information.push(new SimpleDocumentInfo(key, information.info[key])); }); // Meta: info.metadata }); _this.numberOfPages = _this.pdf.numPages; _this.loaded = true; }, function (error) { _this.resetParameters(); _this.onError.emit(error); }); } }; /** * @return {?} */ SimplePdfViewerComponent.prototype.resetParameters = function () { this.information = []; this.outline = null; this.currentPage = 1; this.zoom = 1; this.numberOfPages = 1; this.startAt = SimplePDFBookmark.EMPTY_BOOKMARK; if (this.pdfFindController) { this.pdfFindController.reset(); } }; /** * @param {?} nodes * @return {?} */ SimplePdfViewerComponent.prototype.mapOutline = function (nodes) { var _this = this; return nodes ? nodes.map(function (node) { return new SimpleOutlineNode(node.title, node.dest, _this.mapOutline(node.items)); }, this) : []; }; /** * @return {?} */ SimplePdfViewerComponent.prototype.getContainer = function () { return /** @type {?} */ (this.element.nativeElement.querySelector('div')); }; /** * Returns the basic information about the PDF document * @return {?} */ SimplePdfViewerComponent.prototype.getDocumentInformation = function () { return this.loaded && !!this.information ? this.information : []; }; /** * Returns the value of the viewport scale * @return {?} */ SimplePdfViewerComponent.prototype.getZoom = function () { return this.zoom; }; /** * Returns the value of the viewport scale in % * @return {?} */ SimplePdfViewerComponent.prototype.getZoomPercent = function () { return Math.floor(this.getZoom() * 1000) / 10; }; /** * Increases the scale of the PDF viewport * @return {?} */ SimplePdfViewerComponent.prototype.zoomIn = function () { if (this.isDocumentLoaded()) { this.setZoom(this.zoom + SimplePdfViewerComponent.ZOOM_UNIT); } }; /** * Decreases the scale of the PDF viewport * @return {?} */ SimplePdfViewerComponent.prototype.zoomOut = function () { if (this.isDocumentLoaded()) { this.setZoom(this.zoom - SimplePdfViewerComponent.ZOOM_UNIT); } }; /** * Sets the original viewport scale back to 1.0 * @return {?} */ SimplePdfViewerComponent.prototype.zoomReset = function () { if (this.isDocumentLoaded()) { this.setZoom(1.0); } }; /** * Sets the scale of the PDF viewport to fit in the actual screen * @return {?} */ SimplePdfViewerComponent.prototype.zoomFullPage = function () { var _this = this; if (this.isDocumentLoaded()) { this.pdf.getPage(this.currentPage).then(function (page) { var /** @type {?} */ scale = _this.getScale(page, ScalePriority.FULL); _this.setZoom(scale); }); } }; /** * Sets the scale of the PDF viewport to fit in the actual screen (width priority) * @return {?} */ SimplePdfViewerComponent.prototype.zoomPageWidth = function () { var _this = this; if (this.isDocumentLoaded()) { this.pdf.getPage(this.currentPage).then(function (page) { var /** @type {?} */ scale = _this.getScale(page, ScalePriority.WIDTH); _this.setZoom(scale); }); } }; /** * Sets the scale of the PDF viewport to fit in the actual screen (height priority) * @return {?} */ SimplePdfViewerComponent.prototype.zoomPageHeight = function () { var _this = this; if (this.isDocumentLoaded()) { this.pdf.getPage(this.currentPage).then(function (page) { var /** @type {?} */ scale = _this.getScale(page, ScalePriority.HEIGHT); _this.setZoom(scale); }); } }; /** * @param {?} page * @param {?=} priority * @return {?} */ SimplePdfViewerComponent.prototype.getScale = function (page, priority) { if (priority === void 0) { priority = ScalePriority.FULL; } var /** @type {?} */ viewport = page.getViewport(1, this.rotation); var /** @type {?} */ offsetHeight = this.getContainer().offsetHeight; var /** @type {?} */ offsetWidth = this.getContainer().offsetWidth; if (offsetHeight === 0 || offsetWidth === 0) { return 1; } var /** @type {?} */ heightRatio = (offsetHeight - SimplePdfViewerComponent.PAGE_RESIZE_BORDER_HEIGHT) / viewport.height; var /** @type {?} */ widthRatio = (offsetWidth - SimplePdfViewerComponent.PAGE_RESIZE_BORDER_WIDTH) / viewport.width; var /** @type {?} */ ratio = heightRatio < widthRatio ? heightRatio : widthRatio; if (priority !== ScalePriority.FULL) { ratio = priority === ScalePriority.WIDTH ? widthRatio : heightRatio; } var /** @type {?} */ zoom = 1; return Math.floor(zoom * ratio / SimplePdfViewerComponent.CSS_UNITS * 100) / 100; }; /** * Set the zoom of the document in double * @param {?} scale The zoom value in double * @return {?} */ SimplePdfViewerComponent.prototype.setZoom = function (scale) { if (this.isDocumentLoaded() && typeof scale === 'number') { var /** @type {?} */ normalizedScale = this.normalizeScale(scale); this.pdfViewer._setScale(normalizedScale, false); this.zoom = normalizedScale; } }; /** * Set the zoom of the document in percent * @param {?} zoom The scale value in percent * @return {?} */ SimplePdfViewerComponent.prototype.setZoomInPercent = function (zoom) { if (this.isDocumentLoaded() && typeof zoom === 'number') { this.setZoom(zoom / 100); } }; /** * @param {?} scale * @return {?} */ SimplePdfViewerComponent.prototype.normalizeScale = function (scale) { var /** @type {?} */ normalizedScale = Math.round(scale * 1000) / 1000; if (scale > SimplePdfViewerComponent.MAX_ZOOM) { normalizedScale = SimplePdfViewerComponent.MAX_ZOOM; } else if (scale < SimplePdfViewerComponent.MIN_ZOOM) { normalizedScale = SimplePdfViewerComponent.MIN_ZOOM; } return normalizedScale; }; /** * Starts case sensitive/insensitive text search and navigate to the first match (from the actual page) * @param {?} text searched text * @param {?=} searchOptions set true to use case sensitive searching (false by default) * @return {?} */ SimplePdfViewerComponent.prototype.search = function (text, searchOptions) { if (searchOptions === void 0) { searchOptions = SimpleSearchOptions.DEFAULT_OPTIONS; } if (this.isDocumentLoaded()) { var /** @type {?} */ searchText = text ? text.trim() : ''; if (!searchText) { return; } this.lastSearchText = text; this.searchPrevious = false; this.searchOptions = searchOptions; this.pdfFindController.onUpdateResultsCount = this.onUpdateResultsCount.bind(this); this.pdfFindController.onUpdateState = this.onUpdateState.bind(this); this.pdfFindController.executeCommand(SimplePdfViewerComponent.PDF_FINDER_FIND_COMMAND, { caseSensitive: this.searchOptions.caseSensitive, findPrevious: false, highlightAll: this.searchOptions.highlightAll, phraseSearch: this.searchOptions.phraseSearch, query: searchText }); } }; /** * Navigates to the next search match if there were multiple hits * @return {?} */ SimplePdfViewerComponent.prototype.nextMatch = function () { this.stepMatch(false); }; /** * Navigates to the previous search match if there were multiple hits * @return {?} */ SimplePdfViewerComponent.prototype.previousMatch = function () { this.stepMatch(true); }; /** * @param {?} findPrevious * @return {?} */ SimplePdfViewerComponent.prototype.stepMatch = function (findPrevious) { if (this.isDocumentLoaded() && this.getNumberOfMatches() > 1) { if (this.searchPrevious !== findPrevious) { this.searchPrevious = findPrevious; this.searchAgain(); } else { this.pdfFindController.nextMatch(); this.currentPage = this.pdfViewer._currentPageNumber; } } }; /** * @return {?} */ SimplePdfViewerComponent.prototype.searchAgain = function () { if (this.isDocumentLoaded()) { this.pdfFindController.executeCommand(SimplePdfViewerComponent.PDF_FINDER_AGAIN_COMMAND, { caseSensitive: this.searchOptions.caseSensitive, findPrevious: this.searchPrevious, highlightAll: this.searchOptions.highlightAll, phraseSearch: this.searchOptions.phraseSearch, query: this.lastSearchText }); } }; /** * Returns the number of the search hits * @return {?} */ SimplePdfViewerComponent.prototype.getNumberOfMatches = function () { if (this.isDocumentLoaded()) { return this.pdfFindController.matchCount; } return 0; }; /** * Returns whether there is a matched item * @return {?} */ SimplePdfViewerComponent.prototype.hasMatches = function () { return this.getNumberOfMatches() > 0; }; /** * Returns whether the search is in-progress * @return {?} */ SimplePdfViewerComponent.prototype.isSearching = function () { return this.searching; }; /** * @return {?} */ SimplePdfViewerComponent.prototype.onUpdateResultsCount = function () { this.pdfFindController.onUpdateResultsCount = null; this.currentPage = this.pdfViewer._currentPageNumber; }; /** * @param {?} state * @return {?} */ SimplePdfViewerComponent.prototype.onUpdateState = function (state) { this.onSearchStateChange.emit(state); this.searching = state === SimpleSearchState.PENDING; if (!this.searching) { this.pdfFindController.onUpdateState = null; } }; /** * Returns the number of the actual page * @return {?} */ SimplePdfViewerComponent.prototype.getCurrentPage = function () { return this.currentPage; }; /** * Returns the number of the pages * @return {?} */ SimplePdfViewerComponent.prototype.getNumberOfPages = function () { return this.numberOfPages; }; /** * Returns outline / table of content in tree structure * @return {?} */ SimplePdfViewerComponent.prototype.getOutline = function () { return this.hasOutline() ? this.outline : []; }; /** * Returns whether the outline is available * @return {?} */ SimplePdfViewerComponent.prototype.hasOutline = function () { return this.loaded && !!this.outline && !!this.outline.length; }; /** * Navigates to the specified (outline) destination/chapter * @param {?} destination the destination object of the outline item * @return {?} */ SimplePdfViewerComponent.prototype.navigateToChapter = function (destination) { if (this.isDocumentLoaded()) { // TODO: input validation this.pdfLinkService.navigateTo(destination); } }; /** * Navigates to the first page * @return {?} */ SimplePdfViewerComponent.prototype.firstPage = function () { if (this.isDocumentLoaded()) { this.currentPage = 1; this.navigateToPage(this.currentPage); } }; /** * Navigates to the last page * @return {?} */ SimplePdfViewerComponent.prototype.lastPage = function () { if (this.isDocumentLoaded()) { this.currentPage = this.getNumberOfPages(); this.navigateToPage(this.currentPage); } }; /** * Navigates to the next page * @return {?} */ SimplePdfViewerComponent.prototype.nextPage = function () { if (this.isDocumentLoaded()) { this.currentPage++; this.navigateToPage(this.currentPage, 1); } }; /** * Navigates to the previous page * @return {?} */ SimplePdfViewerComponent.prototype.prevPage = function () { if (this.isDocumentLoaded()) { this.currentPage--; this.navigateToPage(this.currentPage, this.numberOfPages); } }; /** * Navigates to the specified page * @param {?} page the number of the page * @param {?=} pageDefault * @return {?} */ SimplePdfViewerComponent.prototype.navigateToPage = function (page, pageDefault) { if (this.isDocumentLoaded()) { var /** @type {?} */ pageInt = parseInt("" + page, 10); this.currentPage = pageInt ? pageInt : this.currentPage; if (this.currentPage > this.numberOfPages) { this.currentPage = pageDefault ? pageDefault : this.numberOfPages; } if (this.currentPage <= 0) { this.currentPage = pageDefault ? pageDefault : 1; } this.pdfViewer.scrollPageIntoView({ pageNumber: this.currentPage }); } }; /** * Sets the rotation to the default 0 degree * @return {?} */ SimplePdfViewerComponent.prototype.resetRotation = function () { this.rotate(0); }; /** * Turns left the document with 90 degree (counterclockwise) * @return {?} */ SimplePdfViewerComponent.prototype.turnLeft = function () { this.rotate(this.rotation - 90); }; /** * Turns right the document with 90 degree (clockwise) * @return {?} */ SimplePdfViewerComponent.prototype.turnRight = function () { this.rotate(this.rotation + 90); }; /** * Returns the actual rotation value in degree * @return {?} */ SimplePdfViewerComponent.prototype.getRotation = function () { return this.rotation; }; /** * @param {?=} angle * @return {?} */ SimplePdfViewerComponent.prototype.rotate = function (angle) { if (angle === void 0) { angle = 90; } if (this.isDocumentLoaded()) { this.rotation = parseInt("" + angle, 10); if (this.rotation === 270) { this.rotation = -90; } else if (this.rotation === -180) { this.rotation = 180; } this.pdfViewer.pagesRotation = this.rotation; } }; /** * Creates bookmark object based on the current viewport and page number. * The object can be passed to the #navigateToBookmark method. * @return {?} */ SimplePdfViewerComponent.prototype.createBookmark = function () { var _this = this; if (!this.isDocumentLoaded()) { return Promise.reject('Document is not loaded'); } var /** @type {?} */ pagePromise = ((this.pdf.getPage(this.currentPage))); return pagePromise.then(function (page) { var /** @type {?} */ viewport = page.getViewport(1, _this.rotation); var /** @type {?} */ container = _this.getContainer(); var /** @type {?} */ x = container.scrollLeft / container.scrollWidth * viewport.width; var /** @type {?} */ y = (container.scrollHeight - container.scrollTop) / container.scrollHeight * viewport.height; if (_this.rotation === 90) { y = container.scrollTop / container.scrollHeight * viewport.height; var /** @type {?} */ tmp = x; x = y; y = tmp; } else if (_this.rotation === 180) { x = (container.scrollWidth - container.scrollLeft) / container.scrollWidth * viewport.width; y = container.scrollTop / container.scrollHeight * viewport.height; } else if (_this.rotation === -90) { x = (container.scrollWidth - container.scrollLeft) / container.scrollWidth * viewport.width; var /** @type {?} */ tmp = x; x = y; y = tmp; } x = Math.round(x); y = Math.round(y); return new SimplePDFBookmark(_this.currentPage, _this.zoom, _this.rotation, x, y); }); }; /** * Navigates to the specified bookmark * @param {?} bookmark * @return {?} */ SimplePdfViewerComponent.prototype.navigateToBookmark = function (bookmark) { if (this.isDocumentLoaded() && !!bookmark) { this.rotate(bookmark.rotation); this.pdfViewer.scrollPageIntoView(bookmark.toDestination()); } }; /** * Create a snapshot image (PNG) based about the current page * @param {?=} scale the value of the viewport scale, it is 1 by default * @return {?} */ SimplePdfViewerComponent.prototype.getPageSnapshot = function (scale) { var _this = this; if (scale === void 0) { scale = 1; } if (this.isDocumentLoaded()) { var /** @type {?} */ pagePromise = ((this.pdf.getPage(this.currentPage))); return pagePromise.then(function (page) { var /** @type {?} */ viewport = page.getViewport(scale, 0); var /** @type {?} */ canvas = ((document.createElement('canvas'))); var /** @type {?} */ context = canvas.getContext('2d'); canvas.height = viewport.height; canvas.width = viewport.width; var /** @type {?} */ task = ((page.render({ canvasContext: context, viewport: viewport }))); return task.then(function () { return _this.dataURItoFile(canvas.toDataURL(SimplePdfViewerComponent.SNAPSHOT_TPYE)); }); }); } return Promise.reject('Document is not loaded'); }; /** * @param {?} dataURI * @return {?} */ SimplePdfViewerComponent.prototype.dataURItoFile = function (dataURI) { var /** @type {?} */ byteString; if (dataURI.split(',')[0].indexOf('base64') >= 0) { byteString = atob(dataURI.split(',')[1]); } else { byteString = unescape(dataURI.split(',')[1]); } var /** @type {?} */ mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; var /** @type {?} */ ia = new Uint8Array(byteString.length); for (var /** @type {?} */ i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } var /** @type {?} */ blob = new Blob([ia], { type: mimeString }); var /** @type {?} */ b = blob; b.lastModifiedDate = new Date(); b.name = 'screen.png'; return /** @type {?} */ (blob); }; return SimplePdfViewerComponent; }()); SimplePdfViewerComponent.CSS_UNITS = 96.0 / 72.0; SimplePdfViewerComponent.PAGE_RESIZE_BORDER_HEIGHT = 15; SimplePdfViewerComponent.PAGE_RESIZE_BORDER_WIDTH = 15; SimplePdfViewerComponent.ZOOM_UNIT = 0.1; SimplePdfViewerComponent.MAX_ZOOM = 5; SimplePdfViewerComponent.MIN_ZOOM = 0.05; SimplePdfViewerComponent.PDF_FINDER_FIND_COMMAND = 'find'; SimplePdfViewerComponent.PDF_FINDER_AGAIN_COMMAND = 'findagain'; SimplePdfViewerComponent.PDF_VIEWER_DEFAULT_SCALE = 'page-fit'; SimplePdfViewerComponent.SNAPSHOT_TPYE = 'image/png'; SimplePdfViewerComponent.decorators = [ { type: core.Component, args: [{ selector: 'simple-pdf-viewer', template: "
", styles: ["\n :host /deep/ .pdfViewerContainer {\n overflow: auto;\n position: relative;\n width: 100%;\n height: 100%;\n padding: 0;\n margin: 0;\n }\n :host /deep/ .textLayer {\n position: absolute;\n left: 0;\n top: 0;\n right: 0;\n bottom: 0;\n overflow: hidden;\n opacity: 0.2;\n line-height: 1.0;\n }\n :host /deep/ .textLayer > div {\n color: transparent;\n position: absolute;\n white-space: pre;\n cursor: text;\n -webkit-transform-origin: 0% 0%;\n -moz-transform-origin: 0% 0%;\n -o-transform-origin: 0% 0%;\n -ms-transform-origin: 0% 0%;\n transform-origin: 0% 0%;\n }\n :host /deep/ .textLayer .highlight {\n margin: -1px;\n padding: 1px;\n background-color: #002bff;\n border-radius: 4px;\n }\n :host /deep/ .textLayer .highlight.begin {\n border-radius: 4px 0px 0px 4px;\n }\n :host /deep/ .textLayer .highlight.end {\n border-radius: 0px 4px 4px 0px;\n }\n :host /deep/ .textLayer .highlight.middle {\n border-radius: 0px;\n }\n :host /deep/ .textLayer .highlight.selected {\n background-color: rgb(0, 100, 0);\n }\n :host /deep/ .textLayer ::selection { background: #002bff; }\n :host /deep/ .textLayer ::-moz-selection { background: #002bff; }\n :host /deep/ .textLayer .endOfContent {\n display: block;\n position: absolute;\n left: 0px;\n top: 100%;\n right: 0px;\n bottom: 0px;\n z-index: -1;\n cursor: default;\n -webkit-user-select: none;\n -ms-user-select: none;\n -moz-user-select: none;\n }\n :host /deep/ .annotationLayer section {\n position: absolute;\n }\n :host /deep/ .textLayer .endOfContent.active {\n top: 0px;\n }\n :host /deep/ .annotationLayer .linkAnnotation > a {\n position: absolute;\n font-size: 1em;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n }\n :host /deep/ .annotationLayer .linkAnnotation > a:hover {\n opacity: 0.2;\n background: #002bff;\n box-shadow: 0px 2px 10px #002bff;\n }\n :host /deep/ .annotationLayer .linkAnnotation > a /* -ms-a */ {\n background: url(\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\") 0 0 repeat;\n }\n :host /deep/ .annotationLayer .textAnnotation img {\n position: absolute;\n cursor: pointer;\n }\n :host /deep/ .annotationLayer .textWidgetAnnotation input,\n :host /deep/ .annotationLayer .textWidgetAnnotation textarea,\n :host /deep/ .annotationLayer .choiceWidgetAnnotation select,\n :host /deep/ .annotationLayer .buttonWidgetAnnotation.checkBox input,\n :host /deep/ .annotationLayer .buttonWidgetAnnotation.radioButton input {\n background-color: #002bff;\n border: 1px solid transparent;\n box-sizing: border-box;\n font-size: 9px;\n height: 100%;\n padding: 0 3px;\n vertical-align: top;\n width: 100%;\n }\n :host /deep/ .annotationLayer .textWidgetAnnotation textarea {\n font: message-box;\n font-size: 9px;\n resize: none;\n }\n :host /deep/ .annotationLayer .textWidgetAnnotation input[disabled],\n :host /deep/ .annotationLayer .textWidgetAnnotation textarea[disabled],\n :host /deep/ .annotationLayer .choiceWidgetAnnotation select[disabled],\n :host /deep/ .annotationLayer .buttonWidgetAnnotation.checkBox input[disabled],\n :host /deep/ .annotationLayer .buttonWidgetAnnotation.radioButton input[disabled] {\n background: none;\n border: 1px solid transparent;\n cursor: not-allowed;\n }\n :host /deep/ .annotationLayer .textWidgetAnnotation input:hover,\n :host /deep/ .annotationLayer .textWidgetAnnotation textarea:hover,\n :host /deep/ .annotationLayer .choiceWidgetAnnotation select:hover,\n :host /deep/ .annotationLayer .buttonWidgetAnnotation.checkBox input:hover,\n :host /deep/ .annotationLayer .buttonWidgetAnnotation.radioButton input:hover {\n border: 1px solid #000;\n }\n :host /deep/ .annotationLayer .textWidgetAnnotation input:focus,\n :host /deep/ .annotationLayer .textWidgetAnnotation textarea:focus,\n :host /deep/ .annotationLayer .choiceWidgetAnnotation select:focus {\n background: none;\n border: 1px solid transparent;\n }\n :host /deep/ .annotationLayer .textWidgetAnnotation input.comb {\n font-family: monospace;\n padding-left: 2px;\n padding-right: 0;\n }\n :host /deep/ .annotationLayer .textWidgetAnnotation input.comb:focus {\n width: 115%;\n }\n :host /deep/ .annotationLayer .buttonWidgetAnnotation.checkBox input,\n :host /deep/ .annotationLayer .buttonWidgetAnnotation.radioButton input {\n -webkit-appearance: none;\n -moz-appearance: none;\n -ms-appearance: none;\n appearance: none;\n }\n :host /deep/ .annotationLayer .popupWrapper {\n position: absolute;\n width: 20em;\n }\n :host /deep/ .annotationLayer .popup {\n position: absolute;\n z-index: 200;\n max-width: 20em;\n background-color: #FFFF99;\n box-shadow: 0px 2px 5px #333;\n border-radius: 2px;\n padding: 0.6em;\n margin-left: 5px;\n cursor: pointer;\n word-wrap: break-word;\n }\n :host /deep/ .annotationLayer .popup h1 {\n font-size: 1em;\n border-bottom: 1px solid #000000;\n padding-bottom: 0.2em;\n }\n :host /deep/ .annotationLayer .popup p {\n padding-top: 0.2em;\n }\n :host /deep/ .annotationLayer .highlightAnnotation,\n :host /deep/ .annotationLayer .underlineAnnotation,\n :host /deep/ .annotationLayer .squigglyAnnotation,\n :host /deep/ .annotationLayer .strikeoutAnnotation,\n :host /deep/ .annotationLayer .fileAttachmentAnnotation {\n cursor: pointer;\n }\n :host /deep/ .pdfViewer .canvasWrapper {\n overflow: hidden;\n }\n :host /deep/ .pdfViewer .page {\n direction: ltr;\n width: 816px;\n height: 1056px;\n margin: 1px auto -8px auto;\n position: relative;\n overflow: visible;\n border: 9px solid transparent;\n background-clip: content-box;\n border-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAQAAADYWf5HAAAA6UlEQVR4Xl2Pi2rEMAwE16fm1f7/r14v7w4rI0IzLAF7hLxNevBSEMEF5+OilNCsRd8ZMyn+a4NmsOT8WJw1lFbSYgGFzF2bLFoLjTClWjKKGRWpDYAGXUnZ4uhbBUzF3Oe/GG/ue2fn4GgsyXhNgysV2JnrhKEMg4fEZcALmiKbNhBBRFpSyDOj1G4QOVly6O1FV54ZZq8OVygrciDt6JazRgi1ljTPH0gbrPmHPXAbCiDd4GawIjip1TPh9tt2sz24qaCjr/jAb/GBFTbq9KZ7Ke/Cqt8nayUikZKsWZK7Fe6bg5dOUt8fZHWG2BHc+6EAAAAASUVORK5CYII=') 9 9 repeat;\n background-color: white;\n }\n :host /deep/ .pdfViewer.removePageBorders .page {\n margin: 0px auto 10px auto;\n border: none;\n }\n :host /deep/ .pdfViewer.singlePageView {\n display: inline-block;\n }\n :host /deep/ .pdfViewer.singlePageView .page {\n margin: 0;\n border: none;\n }\n :host /deep/ .pdfViewer .page canvas {\n margin: 0;\n display: block;\n }\n :host /deep/ .pdfViewer .page .loadingIcon {\n position: absolute;\n display: block;\n left: 0;\n top: 0;\n right: 0;\n bottom: 0;\n background: url('data:image/gif;base64,R0lGODlhGAAYAPQAAP///wAAAM7Ozvr6+uDg4LCwsOjo6I6OjsjIyJycnNjY2KioqMDAwPLy8nZ2doaGhri4uGhoaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJBwAAACwAAAAAGAAYAAAFriAgjiQAQWVaDgr5POSgkoTDjFE0NoQ8iw8HQZQTDQjDn4jhSABhAAOhoTqSDg7qSUQwxEaEwwFhXHhHgzOA1xshxAnfTzotGRaHglJqkJcaVEqCgyoCBQkJBQKDDXQGDYaIioyOgYSXA36XIgYMBWRzXZoKBQUMmil0lgalLSIClgBpO0g+s26nUWddXyoEDIsACq5SsTMMDIECwUdJPw0Mzsu0qHYkw72bBmozIQAh+QQJBwAAACwAAAAAGAAYAAAFsCAgjiTAMGVaDgR5HKQ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M5wNiV0UN3xdLiqr+mENcWpM9TIbrsBkEck8oC0DQqBQGGIz+t3eXtob0ZTPgNrIwQJDgtGAgwCWSIMDg4HiiUIDAxFAAoODwxDBWINCEGdSTQkCQcoegADBaQ6MggHjwAFBZUFCm0HB0kJCUy9bAYHCCPGIwqmRq0jySMGmj6yRiEAIfkECQcAAAAsAAAAABgAGAAABbIgII4k0DRlmg6kYZCsOg4EKhLE2BCxDOAxnIiW84l2L4BLZKipBopW8XRLDkeCiAMyMvQAA+uON4JEIo+vqukkKQ6RhLHplVGN+LyKcXA4Dgx5DWwGDXx+gIKENnqNdzIDaiMECwcFRgQCCowiCAcHCZIlCgICVgSfCEMMnA0CXaU2YSQFoQAKUQMMqjoyAglcAAyBAAIMRUYLCUkFlybDeAYJryLNk6xGNCTQXY0juHghACH5BAkHAAAALAAAAAAYABgAAAWzICCOJNA0ZVoOAmkY5KCSSgSNBDE2hDyLjohClBMNij8RJHIQvZwEVOpIekRQJyJs5AMoHA+GMbE1lnm9EcPhOHRnhpwUl3AsknHDm5RN+v8qCAkHBwkIfw1xBAYNgoSGiIqMgJQifZUjBhAJYj95ewIJCQV7KYpzBAkLLQADCHOtOpY5PgNlAAykAEUsQ1wzCgWdCIdeArczBQVbDJ0NAqyeBb64nQAGArBTt8R8mLuyPyEAOwAAAAAAAAAAAA==') center no-repeat;\n }\n "] },] }, ]; /** @nocollapse */ SimplePdfViewerComponent.ctorParameters = function () { return [ { type: core.ElementRef, }, { type: http.HttpClient, }, ]; }; SimplePdfViewerComponent.propDecorators = { "src": [{ type: core.Input },], "removePageBorders": [{ type: core.Input },], "disableTextLayer": [{ type: core.Input },], "onLoadComplete": [{ type: core.Output, args: ['onLoadComplete',] },], "onError": [{ type: core.Output, args: ['onError',] },], "onProgress": [{ type: core.Output, args: ['onProgress',] },], "onSearchStateChange": [{ type: core.Output, args: ['onSearchStateChange',] },], }; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var SimplePdfViewerModule = /** @class */ (function () { function SimplePdfViewerModule() { } return SimplePdfViewerModule; }()); SimplePdfViewerModule.decorators = [ { type: core.NgModule, args: [{ imports: [http.HttpClientModule], declarations: [SimplePdfViewerComponent], exports: [SimplePdfViewerComponent] },] }, ]; /** @nocollapse */ SimplePdfViewerModule.ctorParameters = function () { return []; }; exports.SimplePdfViewerModule = SimplePdfViewerModule; exports.SimplePdfViewerComponent = SimplePdfViewerComponent; exports.SimpleSearchState = SimpleSearchState; exports.SimpleDocumentInfo = SimpleDocumentInfo; exports.SimpleOutlineNode = SimpleOutlineNode; exports.SimpleProgressData = SimpleProgressData; exports.SimpleSearchOptions = SimpleSearchOptions; exports.SimplePDFBookmark = SimplePDFBookmark; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=simple-pdf-viewer.umd.js.map