UNPKG

pdff-viewer

Version:
244 lines (243 loc) 7.82 kB
/// <reference types="pdfjs-dist" /> /** * Created by Viktor Hajer on 02/08/2018. */ import { ElementRef, EventEmitter, OnInit, OnDestroy } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { SimpleSearchState, SimpleDocumentInfo, SimpleOutlineNode, SimpleProgressData, SimpleSearchOptions, SimplePDFBookmark } from './simplePdfViewer.models'; /** * Simple PDF Viewer component */ export declare class SimplePdfViewerComponent implements OnInit, OnDestroy { private element; private http; private static readonly CSS_UNITS; private static readonly PAGE_RESIZE_BORDER_HEIGHT; private static readonly PAGE_RESIZE_BORDER_WIDTH; private static readonly ZOOM_UNIT; private static readonly MAX_ZOOM; private static readonly MIN_ZOOM; private static readonly PDF_FINDER_FIND_COMMAND; private static readonly PDF_FINDER_AGAIN_COMMAND; private static readonly PDF_VIEWER_DEFAULT_SCALE; private static readonly SNAPSHOT_TPYE; /** * Source of the PDF document (Required) */ src: string | Uint8Array | PDF.PDFSource; /** * Page border is displayed or not (Optional) */ removePageBorders: boolean; /** * Text layer is displayed or not (Optional) */ disableTextLayer: boolean; onLoadComplete: EventEmitter<void>; onError: EventEmitter<any>; onProgress: EventEmitter<SimpleProgressData>; onSearchStateChange: EventEmitter<SimpleSearchState>; private startAt; private loaded; private currentPage; private numberOfPages; private outline; private information; private zoom; private rotation; private pdf; private pdfLinkService; private pdfViewer; private pdfFindController; private searching; private lastSearchText; private searchPrevious; private searchOptions; constructor(element: ElementRef, http: HttpClient); ngOnInit(): void; ngOnDestroy(): void; /** * 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 */ openDocument(src: string | Uint8Array | PDF.PDFSource, startAt?: SimplePDFBookmark): void; /** * 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 */ openFile(file: File, startAt?: SimplePDFBookmark): void; /** * 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 */ openUrl(url: string, startAt?: SimplePDFBookmark): void; /** * Returns whether the PDF document is loaded properly */ isDocumentLoaded(): boolean; private initPDFJS(); private pagesinitEventListener(); private pagechangeEventListener(); private updateviewareaEventListener(); private setAndParseSrc(src); private loadFile(); private resetParameters(); private mapOutline(nodes); private getContainer(); /** * Returns the basic information about the PDF document */ getDocumentInformation(): SimpleDocumentInfo[]; /** * Returns the value of the viewport scale */ getZoom(): number; /** * Returns the value of the viewport scale in % */ getZoomPercent(): number; /** * Increases the scale of the PDF viewport */ zoomIn(): void; /** * Decreases the scale of the PDF viewport */ zoomOut(): void; /** * Sets the original viewport scale back to 1.0 */ zoomReset(): void; /** * Sets the scale of the PDF viewport to fit in the actual screen */ zoomFullPage(): void; /** * Sets the scale of the PDF viewport to fit in the actual screen (width priority) */ zoomPageWidth(): void; /** * Sets the scale of the PDF viewport to fit in the actual screen (height priority) */ zoomPageHeight(): void; private getScale(page, priority?); /** * Set the zoom of the document in double * @param scale The zoom value in double */ setZoom(scale: number): void; /** * Set the zoom of the document in percent * @param zoom The scale value in percent */ setZoomInPercent(zoom: number): void; private normalizeScale(scale); /** * 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) */ search(text: string, searchOptions?: SimpleSearchOptions): void; /** * Navigates to the next search match if there were multiple hits */ nextMatch(): void; /** * Navigates to the previous search match if there were multiple hits */ previousMatch(): void; private stepMatch(findPrevious); private searchAgain(); /** * Returns the number of the search hits */ getNumberOfMatches(): number; /** * Returns whether there is a matched item */ hasMatches(): boolean; /** * Returns whether the search is in-progress */ isSearching(): boolean; private onUpdateResultsCount(); private onUpdateState(state); /** * Returns the number of the actual page */ getCurrentPage(): number; /** * Returns the number of the pages */ getNumberOfPages(): number; /** * Returns outline / table of content in tree structure */ getOutline(): SimpleOutlineNode[]; /** * Returns whether the outline is available */ hasOutline(): boolean; /** * Navigates to the specified (outline) destination/chapter * @param destination the destination object of the outline item */ navigateToChapter(destination: any): void; /** * Navigates to the first page */ firstPage(): void; /** * Navigates to the last page */ lastPage(): void; /** * Navigates to the next page */ nextPage(): void; /** * Navigates to the previous page */ prevPage(): void; /** * Navigates to the specified page * @param page the number of the page * @param pageDefault */ navigateToPage(page: number, pageDefault?: number): void; /** * Sets the rotation to the default 0 degree */ resetRotation(): void; /** * Turns left the document with 90 degree (counterclockwise) */ turnLeft(): void; /** * Turns right the document with 90 degree (clockwise) */ turnRight(): void; /** * Returns the actual rotation value in degree */ getRotation(): number; private rotate(angle?); /** * Creates bookmark object based on the current viewport and page number. * The object can be passed to the #navigateToBookmark method. */ createBookmark(): Promise<SimplePDFBookmark>; /** * Navigates to the specified bookmark */ navigateToBookmark(bookmark: SimplePDFBookmark): void; /** * Create a snapshot image (PNG) based about the current page * @param scale the value of the viewport scale, it is 1 by default */ getPageSnapshot(scale?: number): Promise<File>; private dataURItoFile(dataURI); }