(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: "