import { PdfViewing } from '../pdf-viewing/PdfViewing'; import { PdfItem, ScrollPosition, MaxScrollPosition, PageImage, PdfPageSize, PdfItemsOnPage, PdfDestination, Point, Rect, PdfRect, StampInfo, PdfPoint, TextFragment, DeletedItem, TextSelection, QuadrilateralOnPage, InputUri, InputFile, ViewOptions, RenderOptions, SaveOptions, PdfViewerApiOptions, AnnotationFilterCallback } from './types'; import { PdfPageLayoutMode, PdfItemCategory, PdfFitMode, RotationDirection } from './enums'; import { Annotation, ScreenPointToPdfPointResult, AnnotationArgs, OutlineItem, StampInfoArgs } from './types'; import { PdfStampSetting } from '../pdf-web-viewer/WebViewerOptions'; export interface RenderCanvasOptions { pageShadow?: CanvasShadowStyles; currentPageShadow?: CanvasShadowStyles; } export interface PdfViewerApiEventMap { firstVisiblePage: number; lastVisiblePage: number; pageNumber: number; rotation: number; zoom: number; fitMode: PdfFitMode; pageLayoutMode: PdfPageLayoutMode; busyState: boolean; unsavedChanges: boolean; canvasInvalidated: boolean; error: Error; itemCreated: PdfItem; itemUpdated: PdfItem; itemDeleted: DeletedItem; pageChanged: number; outlinesLoaded: OutlineItem[]; } export type PdfViewerApiEventListener = (e: PdfViewerApiEventMap[K]) => void; export type PdfViewerApiEventTypes = keyof PdfViewerApiEventMap; export declare class PdfViewerApi { private instance; private eventListeners; private pdfViewerApiOptions; constructor(pdfViewerApiOptions: PdfViewerApiOptions); /** * * Open a PDF and optionally one or more associated FDF's. * @param pdfFile The PDF File that should be opened. * @param fdfFiles A list of FDF or XFDF files associated with this PDF that should be opened. * @param password The password used for opening this file. * @param viewOptions ViewOptions. */ open(pdfFile: InputFile | InputUri, fdfFiles?: (InputFile | InputUri)[] | null, password?: string | null, viewOptions?: ViewOptions | null, renderOptions?: RenderOptions | null, viewportSize?: { width: number; height: number; }): any; /** * Save the currently opened PDF file. * @param fileType Whether the file should be saved as * a PDF containing the document and annotations, * or an FDF containing ONLY the annotations. * * @returns A promise returning a memory buffer containing the saved file if resolved or an error message if rejected. */ save(saveOptions?: SaveOptions): Promise; /** * Close the currently opened PDF file. * @returns A promise returning nothing if resolved and an error message if rejected. */ close(): any; /** * dispose the api. */ destroy(): void; /** * Registers pdf documents to use as stamp * */ registerPdfStampFile(pdfStampFileName: string, data: Uint8Array, onStampCreated: (pdfStamp: PdfStampSetting) => void): void; /** * Clear the rendered pages cache to free memory. */ forceFlushCache(): void; /** * Get the current maximum size of the rendered pages cache. * @returns The current maximum cache size in MB. */ getMaxCacheSize(): number; /** * Set the maximum size of the rendered pages cache. * @param cacheSize The maximum cache size in MB. Default is 120 MB. */ setMaxCacheSize(cacheSize: number): void; /** * Get the total page count of the opened document. * @returns The total number of pages of the currently opened file. * 0 if no document is open. */ getPageCount(): number; /** * Get the page number of the first visible page. * @returns The number of the topmost page shown in the viewport at this moment. */ getPageNumber(): number; getLastVisiblePage(): number; getFirstVisiblePage(): number; /** * Go to a given page. * @param pageNumber The number of the page to be shown in the viewport. */ setPageNumber(pageNumber: number): void; /** * Get the viewer rotation. * @returns The currently used viewer rotation on all pages. */ getRotation(): number; /** * Set the viewer rotation. * NOTE: This only changes the view of the document and is not an operation on the document. * @param rotation The rotation to be applied on all pages (cumulative with the embedded rotation per page). */ setRotation(rotation: number): void; /** * Get the viewer zoom. * @returns The currently used zoom factor. */ getZoom(): number; /** * Set the viewer zoom. * @param zoom The zoom factor as a percentage of the original size. */ setZoom(zoom: number, location?: Point): void; /** * Get the maximum scroll position. * @returns The maximum scroll position in device pixels. */ getScrollMaxPosition(): MaxScrollPosition; /** * Get the current scroll position. * @returns The current scroll position in device pixels. */ getScrollPosition(): ScrollPosition; /** * Set the scroll position. * @param pos The scroll position to be shown in the viewer. */ setScrollPosition(pos: ScrollPosition): void; /** * Jump to a given destination in the document. * @param destination The target destination in PDF coordinates (page origin bottom left) */ goTo(destination: PdfDestination): void; /** * Jump ot a given viewer destination in the document * @param destination The target destination in viewer coordinates (page origin top left) */ goToViewerDestination(destination: PdfDestination): void; /** * Navigate the viewport to show the given Rectangle by scrolling and zooming as little as possible. * @param pdfRect The target destination in PDF coordinates (page origin bottom left) */ goToRectangle(rectangle: PdfRect): void; /** * Check if a document is opened * @returns Whether a file is opened by the viewer. * A file counts as open if opening it has completed successfully * and closing it has not started yet. */ isOpen(): boolean; /** * Set the page layout mode. * @param mode The mode to be used for arranging pages on the canvas. */ setPageLayoutMode(mode: PdfPageLayoutMode): void; /** * Get the current page layout mode. * @returns The mode that is currently used for arranging pages on the canvas. */ getPageLayoutMode(): PdfPageLayoutMode; /** * Set the fit mode. * @param fitMode The mode to be used for fitting the viewport to the visible pages. */ setFitMode(fitMode: PdfFitMode): void; /** * Get the current fit mode. * @returns The mode that is currently used for fitting the viewport to the visible pages. */ getFitMode(): PdfFitMode; /** * Get the size of the border shown in between pages. * @returns The border size in pixels at 100% zoom. */ getBorderSize(): number; /** * Set the size of the border shown in between pages. * @param borderSize The border size in pixels at 100% zoom. */ setBorderSize(borderSize: number): void; /** * Get the sliding window size. * @returns The number of pages the viewer renders before and after the visible pages. */ getSlidingWindowSize(): any; /** * Set the sliding window size. * NOTE: Changing this value will impact caching behavior, because the sliding * window has priority over cache size. This means that the cache can grow beyond * the set cache limit if the sliding window is very large. * @param slidingWindowSize The number of pages the viewer renders before and after the visible pages. */ setSlidingWindowSize(slidingWindowSize: number): void; /** * Suspend drawing for all actions until {@link PdfWebViewer#resumeDrawing|resumeDrawing} is called. */ suspendDrawing(): void; /** * Resume drawing if currently suspended by {@link PdfWebViewer#suspendDrawing|suspendDrawing}. * NOTE: previously given commands that have not yet been executed will not trigger separate render updates. * However, a single render update will be made once all commands before the resumeDrawing call have been executed. */ resumeDrawing(): void; /** * Draw into the canvas to update the viewport. * This method has to be called whenever the canvas has been invalidated or after zoom/scroll. * @param context The canvas context in which the viewer will render. */ renderCanvas(context: CanvasRenderingContext2D, options: RenderCanvasOptions): void; /** * Explicitly render a page with the given dimensions. * The width and height will be adjusted to the aspect ratio of the page, clamping it to the smaller of the two values. * @param pageNumber The number of the page to be rendered. * @param width The width of the output file. * @param height The height of the output file. * @param annotationFilter Optional callback function to filter annotations during rendering. * The result of the callback determines whether the annotation is included in the output. * @returns A promise returning PageImage if resolved or returning an error message if rejected. */ renderPage(pageNumber: number, width: number, height: number, annotationFilter?: AnnotationFilterCallback): Promise; rotatePage(pageNumber: number, direction: RotationDirection): any; /** * Returns the size of a PDF page * @param pageNumber The number of the page. */ getPagePdfSize(pageNumber: number): Promise; /** * Set whether embedded preferences for the startup viewport should be ignored * when opening a PDF file (first shown page, fitmode etc.). * @param ignore Whether the embedded preferences should be ignored. */ setIgnoringPreferences(ignore: boolean): void; /** * Get whether embedded preferences are ignored when opening a PDF file. * @returns Whether embedded preferences are ignored. */ getIgnoringPreferences(): boolean; /** * Get the product version of the viewer. * @returns The product version of the PDF Web Viewer. */ getProductVersion(): string; /** * Load outlines for a given parent. * Can be used to call recursively on children which have descendants. * @param parent The parent outline item. If null then the root outline will be loaded. * @returns A promise with the children of the parent outline. */ getOutlines(parent: OutlineItem | null): any; /** * Get the text fragment located at a given position. * @param point The point in PDF coordinates. * @returns The text fragment or null if no text fragment can be found at the given point. */ getTextFragmentOnPoint(point: Point): TextFragment; /** * Get the text selection for a word located at a given position. * @param point The point in PDF coordinates. * @returns The text selection or null if no word can be found at the given point. */ getWordOnPoint(point: PdfPoint): TextSelection | null; /** * Get the text selection rectangles between the two points. * @param startPoint The starting point of the selection in PDF coordinates. * @param endPoint The end point of the selection in PDF coordinates. * @returns The rectangles of the text fragments contained between the two points. */ getTextSelection(startPoint: PdfPoint, endPoint: PdfPoint): TextSelection | null; /** * Returns a text selection of all text within a rectangle. * @param startPoint The starting point of the selection in PDF coordinates. * @param endPoint The end point of the selection in PDF coordinates. * @returns The rectangles of the text fragments contained between the two points. */ getRectangularTextSelection(startPoint: PdfPoint, endPoint: PdfPoint): TextSelection | null; /** * Get the text between the two points. * @param startPoint The starting point of the selection in PDF coordinates. * @param endPoint The end point of the selection in PDF coordinates. * @returns The string of the selected text. */ getText(startPoint: PdfPoint, endPoint: PdfPoint): string | null; /** * Get the text within a rectangle. * @param startPoint The starting point of the selection in PDF coordinates. * @param endPoint The end point of the selection in PDF coordinates. * @returns The string of the selected text. */ getTextForRectangularSelection(startPoint: PdfPoint, endPoint: PdfPoint): string | null; /** * Get the text contained in given rectangles. * @param selection The rectangles in PDF coordinates. * @returns The string of the selected text. */ /** * Get the annotation located at a given point. * @param point The point in PDF coordinates. * @returns The annotation or null. */ getAnnotationsOnPoint(point: Point, onlySelectable?: boolean): Annotation[]; /** * Get all open popups from to . * @param firstPage The first page. * @param lastPage The last page. * @returns The list of annotations with an open popup in the given range. */ getOpenPopups(firstPage: number, lastPage: number): Annotation[]; /** * Load items of type {@link PdfItemCategory} for a given page. * @param page The page for which the items should be loaded. * @param type The type of item to be loaded. See {@link PdfItemCategory}. * @returns The list of items. */ getItemsFromPage(page: number, category: PdfItemCategory): Promise; /** * Create an annotation. * Depending on the type of annotation the annotation args have to contain different arguments. * See: * {@link TextStampAnnotationArgs} * {@link InkAnnotationArgs} * {@link FreeTextAnnotationArgs} * @param itemArgs The arguments specific to the type of item to be created. * @returns The created item. */ createItem(itemArgs: AnnotationArgs): Promise; /** * Get the item for a given id. * @param id The id of the item. * @returns A promise returning the item if resolved or returning an error message if rejected. */ getItem(id: number): PdfItem | null; /** * Get the objects for given ids. * @param ids The ids of the items. * @returns A promise returning a list of items if resolved or returning an error message if rejected. */ getItems(ids: number[]): PdfItem[]; /** * Update the editable fields of an item (e.g. an annotation). * Please check the manual for more information about items and their fields. * @param item The item to be updated. * @returns A promise returning the updated item if resolved or returning an error message if rejected. */ updateItem(item: PdfItem): Promise; /** * Delete an item (e.g. an annotation). * Please check the manual for more information about items. * @param item The item to be deleted. * @returns A promise returning nothing if resolved or returning an error message if rejected. */ deleteItem(item: PdfItem): Promise; /** * Get information about a particular stamp. * Used for text stamps to retrieve the aspect ratio of the resulting stamp. * @param args stampType should be TEXT - stampText is the text of the stamp that should be displayed on the stamp annotation. * @returns A promise returning stamp information such as aspect ratio if resolved. */ getStampInfo(args: StampInfoArgs): Promise; getTextStampAspectRatio(stampText: string): Promise; /** * Register an image stamp in the document. If the registration is successful the promise * returns an ID > 0. This ID can then be used for the createItem method to create an image stamp * with the given image ID * @param image * @returns A promise returning the ID */ registerStampImage(image: Uint8Array): Promise; /** * Register an pdf page as stamp in the document. If the registration is successful the promise * returns an ID > 0. This ID can then be used for the createItem method to create an image stamp * with the given ID * @param image * @returns A promise returning the ID */ registerPdfPage(fileName: string, pageNumber: number): Promise; /** * Check whether there are unsaved changes in the document. * NOTE: When saving a document with unsaved changes * - is successful: the promise resolves and the document is considered to be saved even if the array buffer with the saved document is discarded. * - fails: the document is considered to contain unsaved changes. * @returns True if there are unsaved changes, false otherwise. */ hasChanges(): any; /** * @param searchString The string to be searched for. * @param startPage The page on which the search is started. * @param caseSensitive Whether the search should match case. * @param wrapSearch Whether the search should wrap around to the beginning when the end of the document is reached. * @param useRegex Whether the search should interpret the provided string as a regular expression. * @returns A promise returning a {@link SearchResult} if resolved or returning an error message if rejected. */ getSearchIterator(searchString: string, startPage: number, caseSensitive: boolean, wrapSearch: boolean, useRegex: boolean): PdfViewing.Pdf.Content.TextSearchIterator; /** * Set the license key for the viewer. * @param license The license key. * @returns True if license is correct else false */ setLicenseKey(license: string): boolean; /** internal */ getSupportedFeatures(): PdfViewing.LicenseFeature; /** * Convert a point from device coordinates to PDF coordinates. * @param point The point in device coordinates. * @param page The page relative to which the PDF coordinates should be calculated. * @param guaranteePointIsOnPage This parameter will fix the isOnPage boolean of the return value to true. * Due to conversions back and forth from CSS to PDF and vice versa, * a CSS coordinate could return isOnPage=False even if the mouse movement * has been restricted to the page. Only set this to true if the * device point is certainly on the page. * @returns The point in PDF coordinates, including the number of the page where it is located. */ transformScreenPointToPdfPoint(point: Point, page?: number, guaranteePointIsOnPage?: boolean): ScreenPointToPdfPointResult; getClosestPointOnPdfByScreenPoint(point: Point, padding?: number, page?: number): PdfPoint; transformPdfPointToScreenPoint(pdfPoint: PdfPoint): Point; /** * Convert a rectangle from device coordinates to PDF coordinates. * @param rect The rectangle in device coordinates. * @returns The rectangle in PDF coordinates, including the number of the page where it is located. */ transformScreenRectToPdfRect(rect: Rect, page: number): PdfRect; /** * Convert a rectangle from PDF coordinates to device coordinates. * @param pdfRect The rectangle in PDF coordinates. * @returns Rect The rectangle in device coordinates. */ transformPdfPageRectToScreenRect(pdfRect: PdfRect): Rect; /** * Convert a length from PDF units to device pixels. * @param pdfLength The length in PDF units. * @returns number The length in device pixels. */ transformPdfLengthToScreenLength(pdfLength: number): number; /** * Convert a length from device pixels to PDF units. * @param screenLength The length in device pixels. * @returns number The length in PDF units. */ transformScreenLengthToPdfLength(screenLength: number): number; /** * Convert a length from PDF units to device pixels. * @param pdfLength The length in PDF units. * @returns number The length in device pixels. */ transformQuadrilateralToViewport(quadrilateral: QuadrilateralOnPage): Point[]; /** * Get the screen rectangle of a page to know its position inside the viewport. * @param pageNumber The number of the page. * @returns The rectangle with the page coordinates in device pixels. * Null if no document is opened or the page is invalid. */ getPageScreenRect(pageNumber: number): Rect; addEventListener(type: K, listener: (e: PdfViewerApiEventMap[K]) => void): void; removeEventListener(type: K, listener: (e: PdfViewerApiEventMap[K]) => void): void; }