UNPKG

@mescius/dspdfviewer

Version:
1,239 lines (1,238 loc) 47.6 kB
import { GcSelectionPoint } from "./GcMeasurementTypes"; /** * Information about the document signature that will be used to sign the document. * @example * Send a request to the server to save the document with signature. * ```javascript * viewer.save("test.pdf", { sign: { signatureField: "field1", signerName: "John Doe" } } ); * ``` * @example * Example of server side signing implementation * ```csharp * // Example: electronically sign PDFs with a .PFX certificate: * * public void Configuration(IAppBuilder app) { * GcPdfViewerController.Settings.Sign += _OnSign; * // ... * } * * private void _OnSign(object sender, SignEventArgs e) * { * var signatureProperties = e.SignatureProperties; * X509Certificate2 certificate = new X509Certificate2(System.IO.File.ReadAllBytes("certificate.pfx"), "password", * X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable); * signatureProperties.SignatureBuilder = new Pkcs7SignatureBuilder() * { * CertificateChain = new X509Certificate2[] { certificate }, * HashAlgorithm = Security.OID.HashAlgorithms.SHA512, * Format = Pkcs7SignatureBuilder.SignatureFormat.adbe_pkcs7_detached * }; * } * ``` **/ export type SignatureInfo = { /** * The information provided by the signer to enable a recipient to contact the signer to verify the signature (for example, a phone number). **/ contactInfo: string; /** * The CPU host name or physical location of the signing. **/ location: string; /** * The name of the person or authority signing the document. * NOTE: This value is used only if it is not possible to extract the name from the signature, for example from the certificate of the signer. **/ signerName: string; /** * The reason for the signing, such as "I agree...". **/ reason: string; /** * The signature field name used to store a digital signature. **/ signatureField: string; }; /** * Form field appearance rendering type. * "Custom" - use custom appearance. The custom appearance has some improvements over the web appearance, * for example you can specify background / border colors. * "Web" - use standard field appearance using platform-native styling. See https://developer.mozilla.org/en-US/docs/Web/CSS/appearance for details. * "Predefined" - use predefined appearance stream from PDF when available, if appearance stream is not available, custom appearance will be used. **/ export type FieldAppearanceRenderingType = "Custom" | "Web" | "Predefined"; /** * Document initialization / loading parameters object. * @ignore exclude from docs. * * @typedef {Object} DocumentInitParameters * @property {string|URL} [url] - The URL of the PDF. * @property {TypedArray|Array<number>|string} [data] - Binary PDF data. Use * typed arrays (Uint8Array) to improve the memory usage. If PDF data is * BASE64-encoded, use `atob()` to convert it to a binary string first. * @property {Object} [httpHeaders] - Basic authentication headers. * @property {boolean} [withCredentials] - Indicates whether or not * cross-site Access-Control requests should be made using credentials such * as cookies or authorization headers. The default is `false`. * @property {string} [password] - For decrypting password-protected PDFs. * @property {TypedArray} [initialData] - A typed array with the first portion * or all of the pdf data. Used by the extension since some data is already * loaded before the switch to range requests. * @property {number} [length] - The PDF file length. It's used for progress * reports and range requests operations. * @property {PDFDataRangeTransport} [range] - Allows for using a custom range * transport implementation. * @property {number} [rangeChunkSize] - Specify maximum number of bytes fetched * per range request. The default value is {@link DEFAULT_RANGE_CHUNK_SIZE}. * @property {PDFWorker} [worker] - The worker that will be used for loading and * parsing the PDF data. * @property {number} [verbosity] - Controls the logging level; the constants * from {@link VerbosityLevel} should be used. * @property {string} [docBaseUrl] - The base URL of the document, used when * attempting to recover valid absolute URLs for annotations, and outline * items, that (incorrectly) only specify relative URLs. * @property {string} [cMapUrl] - The URL where the predefined Adobe CMaps are * located. Include the trailing slash. * @property {boolean} [cMapPacked] - Specifies if the Adobe CMaps are binary * packed or not. * @property {Object} [CMapReaderFactory] - The factory that will be used when * reading built-in CMap files. Providing a custom factory is useful for * environments without Fetch API or `XMLHttpRequest` support, such as * Node.js. The default value is {DOMCmapReaderFactory}. * @property {boolean} [useSystemFonts] - When `true`, fonts that aren't * embedded in the PDF document will fallback to a system font. * The default value is `true` in web environments and `false` in Node.js; * unless `disableFontFace === true` in which case this defaults to `false` * regardless of the environment (to prevent completely broken fonts). * @property {string} [standardFontDataUrl] - The URL where the standard font * files are located. Include the trailing slash. * @property {Object} [StandardFontDataFactory] - The factory that will be used * when reading the standard font files. Providing a custom factory is useful * for environments without Fetch API or `XMLHttpRequest` support, such as * Node.js. The default value is {DOMStandardFontDataFactory}. * @property {boolean} [useWorkerFetch] - Enable using the Fetch API in the * worker-thread when reading CMap and standard font files. When `true`, * the `CMapReaderFactory` and `StandardFontDataFactory` options are ignored. * The default value is `true` in web environments and `false` in Node.js. * @property {boolean} [stopAtErrors] - Reject certain promises, e.g. * `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated * PDF data cannot be successfully parsed, instead of attempting to recover * whatever possible of the data. The default value is `false`. * @property {number} [maxImageSize] - The maximum allowed image size in total * pixels, i.e. width * height. Images above this value will not be rendered. * Use -1 for no limit, which is also the default value. * @property {boolean} [isEvalSupported] - Determines if we can evaluate strings * as JavaScript. Primarily used to improve performance of font rendering, and * when parsing PDF functions. The default value is `true`. * @property {boolean} [disableFontFace] - By default fonts are converted to * OpenType fonts and loaded via the Font Loading API or `@font-face` rules. * If disabled, fonts will be rendered using a built-in font renderer that * constructs the glyphs with primitive path commands. * The default value is `false` in web environments and `true` in Node.js. * @property {boolean} [fontExtraProperties] - Include additional properties, * which are unused during rendering of PDF documents, when exporting the * parsed font data from the worker-thread. This may be useful for debugging * purposes (and backwards compatibility), but note that it will lead to * increased memory usage. The default value is `false`. * @property {boolean} [enableXfa] - Render Xfa forms if any. * The default value is `false`. * @property {HTMLDocument} [ownerDocument] - Specify an explicit document * context to create elements with and to load resources, such as fonts, * into. Defaults to the current document. * @property {boolean} [disableRange] - Disable range request loading of PDF * files. When enabled, and if the server supports partial content requests, * then the PDF will be fetched in chunks. The default value is `false`. * @property {boolean} [disableStream] - Disable streaming of PDF file data. * By default PDF.js attempts to load PDF files in chunks. The default value * is `false`. * @property {boolean} [disableAutoFetch] - Disable pre-fetching of PDF file * data. When range requests are enabled PDF.js will automatically keep * fetching more data even if it isn't needed to display the current page. * The default value is `false`. * * NOTE: It is also necessary to disable streaming, see above, in order for * disabling of pre-fetching to work correctly. * @property {boolean} [pdfBug] - Enables special hooks for debugging PDF.js * (see `web/debugger.js`). The default value is `false`. */ export type DocumentInitParameters = { url?: string | URL; data?: any | Array<number> | string; httpHeaders?: Object; initialData?: any; length?: number; range?: any; rangeChunkSize?: number; worker?: any; verbosity?: number; docBaseUrl?: string; cMapUrl?: string; cMapPacked?: boolean; CMapReaderFactory?: Object; useSystemFonts?: boolean; standardFontDataUrl?: string; StandardFontDataFactory?: Object; useWorkerFetch?: boolean; stopAtErrors?: boolean; maxImageSize?: number; isEvalSupported?: boolean; disableFontFace?: boolean; fontExtraProperties?: boolean; enableXfa?: boolean; ownerDocument?: any; disableRange?: boolean; disableStream?: boolean; disableAutoFetch?: boolean; pdfBug?: boolean; }; /** * Open parameters. **/ export type OpenParameters = { /** * Authentication headers. **/ headers?: { [header: string]: string; }; /** * Indicates whether or not * cross-site Access-Control requests should be made using credentials such * as cookies or authorization headers. The default is `false`. * withCredentials makes the browser include cookies and authentication headers in the XHR request. * If your service depends on any cookie (including session cookies), it will only work with this option set. **/ withCredentials?: boolean; /** * For decrypting password-protected PDFs. **/ password?: string; /** * @ignore exclude from docs **/ friendlyPdfUrl?: string; } & DocumentInitParameters; /** * Represents an Optional Content Configuration (OCConfig) in a PDF document. * This configuration defines the visibility and behavior of Optional Content Groups (OCGs). * * Based on ISO 32000-2, an Optional Content Configuration manages: * - The default state of OCGs. * - The visibility order of layers. * - Application-specific metadata. */ export type OptionalContentConfig = { /** * The name of the application or process that created this configuration. * Can be `null` if unspecified. */ creator: null | string; /** * A user-friendly name for this configuration. * Can be `null` if unnamed. */ name: null | string; /** * Retrieves an Optional Content Group (OCG) by its unique identifier. * * @param id - The ID of the content group. * @returns The corresponding `OptionalContentGroup`, or throws an error if not found. */ getGroup(id: string): OptionalContentGroup; /** * Retrieves all Optional Content Groups (OCGs) defined in the document. * * @returns An object where the keys are group IDs and the values are `OptionalContentGroup` instances. */ getGroups(): { [id: string]: OptionalContentGroup; }; /** * Retrieves the order in which Optional Content Groups should be displayed in the layers panel. * * This can be: * - An array of string IDs representing a simple ordered list of groups. * - An array of objects containing a `name` and an `order`, where `order` is a list of grouped layers. * * @returns The configured display order of the groups. */ getOrder(): (string | { name: string | null; order: string[]; })[]; /** * Checks whether an Optional Content Group (OCG) is currently visible. * * @param groupOrId - The group instance or its ID. * @returns `true` if the group is visible, otherwise `false`. */ isVisible(groupOrId: string | OptionalContentGroup): boolean; /** * Sets the visibility state of an Optional Content Group (OCG). * * @param id - The ID of the content group. * @param visible - `true` to make the group visible, `false` to hide it. */ setVisibility(id: string, visible: boolean): void; /** * Defines the scaling factor applied when viewing optional content. * This is used to determine the effective visibility of OCGs based on zoom levels. */ viewScale: number; }; /** * Represents an Optional Content Group (OCG), also known as a "Layer" in a PDF document. * OCGs allow content to be dynamically shown or hidden based on user interactions or viewing conditions. * Defined in ISO 32000-2. */ export type OptionalContentGroup = { /** * The unique identifier of the optional content group. */ id: string; /** * The display name of the optional content group. */ name: string; /** * The type of the optional content group. * "OCG" (Optional Content Group) is the standard type, but custom types may be used. */ type: "OCG" | string; /** * The current visibility state of the group in the viewer. * This does not necessarily reflect its default state in the document. */ visible: boolean; /** * The export state of the group. * If `"ON"`, content in this group should be included in exported output (e.g., saving, flattening). * If `"OFF"`, content in this group should be excluded from export. */ exportState?: "ON" | "OFF"; /** * The initial view state of the group when the document is opened. * If `"ON"`, the group is visible by default. * If `"OFF"`, the group is hidden by default. */ viewState?: "ON" | "OFF"; /** * The print state of the group. * If `"ON"`, the group will be printed. * If `"OFF"`, the group will be hidden in printed output. */ printState?: "ON" | "OFF"; /** * Metadata about the application that created the optional content group. * This is an optional dictionary that stores application-specific data. */ creatorInfo?: { /** * The name of the application that created the group. */ Creator: string; /** * The intended content type of the group. * Suggested values include: * - `"Artwork"` - for graphic design or publishing applications. * - `"Technical"` - for technical drawings such as schematics or architectural plans. */ Subtype: string; }; /** * Specifies the intended use of the graphics in this group. * A PDF processor may selectively render content based on this intent. * * - `"View"`: Intended for on-screen viewing (default). * - `"Design"`: Intended for design-related content. * * If `"Design"` is specified, a `creatorInfo` entry should also be included. */ intent?: "View" | "Design"; /** * Defines a range of zoom levels at which this optional content group should be visible. */ zoom?: { /** * The minimum zoom level at which the group should be visible. * Default: `0` (always visible at any zoom level). */ min?: number; /** * The maximum zoom level beyond which the group should be hidden. * Default: `Infinity` (always visible at any zoom level). */ max?: number; }; }; /** * Structure tree node. The root node will have a role "Root". **/ export type StructTreeNode = { /** * @property {string} role - element's role, already mapped if a role map exists * in the PDF. **/ role: "Root" | string; /** * @property {Array<StructTreeNode | StructTreeContent>} children - Array of * {@link StructTreeNode} and {@link StructTreeContent} objects. **/ children: Array<StructTreeNode | StructTreeContent>; }; /** * Structure tree content. **/ export type StructTreeContent = { /** * @property {string} id - unique id that will map to the text layer. **/ id: string; /** * @property {string} type - either "content" for page and stream structure * elements or "object" for object references. **/ type: "content" | "object"; /** * Actual content text. **/ actualText: string | undefined; }; /** * The name of the GcPdfViewer's feature. * Used by the disableFeatures option. * Available feature names: 'JavaScript', 'AllAttachments', 'FileAttachments', 'SoundAttachments', 'DragAndDrop', 'SubmitForm', 'Print', * 'Open', 'Layers', 'CustomFonts', 'Redact', 'ConvertToContent', 'NewDocument', 'NewPage', 'DeletePage', 'PdfOrganizer', 'ReplaceText', 'ESign', 'Save', 'SaveToPng', 'SaveToSvg', 'Collaboration'. **/ export type ViewerFeatureName = 'JavaScript' | 'AllAttachments' | 'FileAttachments' | 'SoundAttachments' | 'RichMediaAttachments' | 'DragAndDrop' | 'SubmitForm' | 'Print' | 'Open' | 'Layers' | 'CustomFonts' | 'Redact' | 'ConvertToContent' | 'NewDocument' | 'NewPage' | 'DeletePage' | 'PdfOrganizer' | 'ReplaceText' | 'ESign' | 'Save' | 'SaveToPng' | 'SaveToSvg' | 'Collaboration' | 'Linearization' | 'IncrementalUpdate' | 'RichText' | 'TableDataExtraction'; /** * Image stamp category data model. **/ export type StampCategory = { /** * Category identifier. **/ id?: string; /** * Category display name. **/ name: string; /** * Stamp image names. **/ stampImages?: string[]; /** * Optional. Full URIs for image stamps. * If specified, the stampImageUrls settings will be used instead of the stampImages array. **/ stampImageUrls?: string[]; /** * Indicates whether the category contains dynamic stamps. * Dynamic stamp images are updated for each new stamp instance. **/ isDynamic?: boolean; /** * Optional. Images resolution. * @default 72. **/ dpi?: number; }; /** * Page viewport information. * @ignore exclude **/ export interface IPageViewport { /** * X offset. * Default: 0. **/ offsetX: number; /** * Y offset. * Default: 0 **/ offsetY: number; /** * Rotation in degrees. **/ rotation: number; /** * Viewport scale factor. **/ scale: number; /** * Viewport transform matrix. * Example value (page scale is 60%): * (6) [0.6666666666666666, 0, 0, -0.6666666666666666, 0, 528] **/ transform: number; /** * Viewbox without scale. Origin is bottom left. * [x1, y1, x2, y2] * Default value: [0, 0, 612, 792] **/ viewBox: number[]; /** * Viewport width including scale. **/ width: number; /** * Viewport height including scale. **/ height: number; } /** * Page view interface. * @ignore exclude **/ export interface IGcPageView { /** * Page view viewport information. **/ viewport: IPageViewport; ensureFullyLoaded(): Promise<IGcPageView>; /** * Ensure selection painter is loaded. Used only when canvas selection is enabled. * */ ensureSelectionPainter(): Promise<any>; ensureAnnotationLayerRendered(): Promise<any>; pageIndex: number; width: number; height: number; renderingId: string; renderingState: any; /** * gets device scale * */ outputScale: any; /** * Current page scale value. read only. * */ scale: number; /** * Current page rotation value. read only. * */ rotation: number; /** * Indicates whether the annotation layer is dirty. * When this property is `true`, it triggers the need for re-rendering the annotation layer * in the page view, irrespective of the renderingState being FINISHED. */ annotationLayerDirty?: boolean; } /** * @ignore exclude **/ export interface IGcVisiblePage { /** * Page index. **/ id: number; view: IGcPageView; x: number; y: number; /** * Example 54%: 54 **/ percent: number; } /** * @ignore exclude **/ export interface IGcVisiblePagesInfo { first: IGcVisiblePage; last: IGcVisiblePage; views: IGcVisiblePage[]; } /** * Interface for handling auto-scrolling behavior. * @ignore exclude from docs. */ export interface IAutoScrollHelper { /** * Starts the scrolling behavior based on the given event. * * @param {MouseEvent | TouchEvent} e - The event that triggers the scrolling. * @param {Object} [args] - Optional parameters. * @param {number} [args.pageRotation=0] - The page rotation in degrees. * @param {"both" | "horizontal" | "vertical"} [args.allowedDirections="vertical"] - The allowed scrolling directions. */ start(e: MouseEvent | TouchEvent | PointerEvent, args?: { pageRotation?: number; allowedDirections?: "both" | "horizontal" | "vertical"; }): void; /** * Stops the scrolling behavior. */ stop(): void; getScrollPos(): { scrollLeft: number; scrollTop: number; }; } export interface IGcSelectionCopier { showTextMarkupContextMenu(event: MouseEvent | TouchEvent, coords?: { clientX: number; clientY: number; }): boolean; showCustomContextMenu(event: MouseEvent | TouchEvent, coords?: { clientX: number; clientY: number; }): boolean; copySelectedText(): boolean; printSelectedText(): any; resetAll(): any; resetPage(pageIndex: number): any; beginUpdatePages(): any; endUpdatePages(): any; beginUpdatePage(pageIndex: number): any; endUpdatePage(): any; getSelectedText(): any; lastCaretPos: GcSelectionPoint; lastMousePos: GcSelectionPoint; notifyCaretPositionChanged(x: number, y: number, pageIndex: number): any; notifyViewerFocused(viewer: any): any; onNativeContextMenuStart(): any; onNativeContextMenuEnd(): any; hasSelectedText: boolean; currentSelectionBox: null | { pageIndex: number; x: number; y: number; w: number; h: number; paintedBoxes: { pageIndex: number; x: number; y: number; w: number; h: number; angle: number; dir: "ltr" | "rtl"; vertical: boolean; itemData: any; }[]; }; } /** * Additional save settings. **/ export type SaveSettings = { /** * Destination document format. * PDF - the document will be saved in PDF format. * PNG - the document will be saved to PNG images. * SVG - the document will be saved to SVG images. * @default PDF. * @example * Save the document as SVG images * ```javascript * await viewer.save("sample.zip", { format: "SVG" }); * ``` * @example * Save document pages as PNG images * ```javascript * await viewer.save("sample.zip", { format: "SVG" }); * ``` **/ format?: "PDF" | "PNG" | "SVG"; /** * You can specify the index of the page(s) or pages range to save. * For a range of pages, use a hyphen. Separate page or pages range with a comma, e.g. "0, 1, 4-5, 8". * You can also change the page order: "1, 0, 2-8", * clone required pages: "0, 0, 3, 3, 3", * specify external pdf file as source: "0-3, [file:fileid_1]0-3, [file:fileid_1]5-7, [file:fileid_2]0-3" (see examples for details), * or rotate page(s): await viewer.save("test_part10.pdf", { reload: true, pages: "[angle:90]2-3" }); * @example * ```javascript * // Save six pages with indices: 0, 1, 2, 3, 7, 9: * await viewer.save("test_part10.pdf", { reload: true, pages: "0-3, 7, 9" }); * ``` * @example * ```javascript * // Rotate 90 degrees and save 2 pages with indices 2 and 3: * await viewer.save("test_part10.pdf", { reload: true, pages: "[angle:90]2-3" }); * ``` * @example * ```javascript * // Invoke the system file picker dialog * // to select an external PDF file to merge. * // Then, merge first page from selected PDF document and * // download result PDF file to local system. * var fileInput = document.createElement('input'); * fileInput.type = 'file'; * fileInput.accept = ".pdf"; * fileInput.style.display = 'none'; * fileInput.onchange = function () { * if (fileInput.files && fileInput.files[0]) { * var fileReader = new FileReader(); * fileReader.onload = function () { * const fileId = "uniquefileid_" + new Date().getTime(); * viewer.storage.setItem(fileId, new Uint8Array(fileReader.result)); * // Merge first page from external PDF document * // to the end of the active PDF document * // and download result PDF file: * await viewer.save("sample.pdf", * { pages: `0-${viewer.pageCount - 1}, [file:${fileId}]0` }); * }; * fileReader.readAsArrayBuffer(fileInput.files[0]); * } * }; * document.body.appendChild(fileInput); * fileInput.click(); * ``` **/ pages?: string; /** * Load the updated PDF document into the viewer without downloading it to the local system. * @example0 * ```javascript * // Save dodument and load saved document into the viewer: * await viewer.save("test_part10.pdf", { reload: true }); * ``` **/ reload?: boolean; /** * Defines the mode of saving a PDF. * @default Auto the PDF is not linearized and the incremental update will be used only for signed PDF documents. **/ saveMode?: "Auto" | "Default" | "Linearized" | "IncrementalUpdate"; /** * Save modifications to server without downloading file to local disk. * @default false * @ignore excluded from documentation, used for internal purposes. **/ saveModificationsOnly?: boolean; /** * Signature settings used to save document with signature. * If specified, the document will be saved with signature. **/ sign?: SignatureInfo; /** * Custom progress title to be displayed during save. * ```javascript * viewer.save("sample.pdf", { pages: "[angle:90]0,1-5", progressTitle: "Rotating" }, reload: true); * ``` **/ progressTitle?: string; /** * Custom progress message to be displayed during save. * ```javascript * viewer.save("sample.pdf", { pages: "[angle:90]0,1-5", progressMessage: "Rotating first page..." }, reload: true); * ``` **/ progressMessage?: string; /** * Zoom factor to be used for rendering images when the target format is "PNG". * ```javascript * viewer.save("sample.pdf", { format: "PNG", zoomFactor: 1.5 }); * ``` **/ zoomFactor?: number; }; /** * PDF page viewport created based on scale, rotation and offset. **/ export type PageViewport = { /** * viewBox **/ viewBox: number[]; /** * width **/ width: number; /** * height **/ height: number; /** * scale **/ scale: number; rotation: number; offsetX: number; offsetY: number; /** * Viewport transform. **/ transform: number[]; /** * Clone viewport. **/ clone(args: Partial<PageViewport>): PageViewport; /** * Converts PDF point to the viewport coordinates. Useful for converting PDF location (bottom/left) into canvas pixel coordinates(top/left). * @param {number} x - The x-coordinate. * @param {number} y - The y-coordinate. **/ convertToViewportPoint(x: number, y: number): number[]; /** * Converts PDF rectangle to the viewport coordinates. * @param {Array} rect - The xMin, yMin, xMax and yMax coordinates. **/ convertToViewportRectangle(rect: number[]): number[]; /** * Converts viewport coordinates to the PDF location. Useful for converting canvas pixel location(top/left) into PDF location (bottom/left). * @param {number} x - The x-coordinate. * @param {number} y - The y-coordinate. **/ convertToPdfPoint(x: any, y: any): number[]; }; /** * A viewer preferences specifying the way the document shall be displayed on the screen. **/ export type ViewerPreferences = { /** * A flag specifying whether to hide the interactive PDF processor’s tool bars when the document is active. Default value: false. **/ hideToolbar?: boolean; /** * A flag specifying whether to hide the interactive PDF processor’s menu bar when the document is active. Default value: false. **/ hideMenubar?: boolean; /** * A flag specifying whether to hide user interface elements in the document’s window (such as scroll bars and navigation controls), leaving only the document’s contents displayed. **/ hideWindowUI?: boolean; /** * A flag specifying whether to resize the document’s window to fit the size of the first displayed page. **/ fitWindow?: boolean; /** * A flag specifying whether to position the document’s window in the centre of the screen. **/ centerWindow?: boolean; /** * A flag specifying whether the window’s title bar should display the document title taken from the dc:title element of the XMP metadata stream (see 14.3.2, "Metadata streams"). If false, the title bar should instead display the name of the PDF file containing the document. **/ displayDocTitle?: boolean; /** * The document’s page mode, specifying how to display the document on exiting full-screen mode **/ nonFullScreenPageMode?: PageMode; /** * (PDF 1.1) A value specifying a destination that shall be displayed or an action that shall be performed when the document is opened. The value shall be either an array defining a destination (see 12.3.2, "Destinations") or an action dictionary representing an action (12.6.2, "Action dictionaries"). If this entry is absent, the document shall be opened to the top of the first page at the default magnification factor. **/ openAction?: OpenAction; /** * A name object specifying how the document shall be displayed when opened: * * UseNone Neither document outline nor thumbnail images visible * * UseOutlines Document outline visible * * UseThumbs Thumbnail images visible * * FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible * * UseOC (PDF 1.5) Optional content group panel visible * * UseAttachments (PDF 1.6) Attachments panel visible * Default value: UseNone. **/ pageMode?: PageMode; /** * A name object specifying the page layout shall be used when the document is opened. * The following pageLayout values specified in the PDF document correspond to the pageDisplay values in the viewer: * * TwoColumnLeft: This sets pageDisplay to TwoPageScrolling. * * TwoColumnRight: This sets pageDisplay to TwoPageScrolling. * * TwoPageLeft: This sets pageDisplay to TwoPage. * * TwoPageRight: This sets pageDisplay to TwoPage. * * OneColumn: This sets pageDisplay to SinglePageScrolling. * * SinglePage: This sets pageDisplay to SinglePage. **/ pageLayout?: PageLayout; }; /** * Initial page mode preference. **/ export type PageMode = "UseAttachments" | "UseOC" | "UseOutlines" | "UseThumbs" | "UseNone" | "FullScreen" | ""; /** * Initial page layout preference. **/ export type PageLayout = "SinglePage" | "OneColumn" | "TwoColumnLeft" | "TwoColumnRight" | "TwoPageRight" | "TwoPageLeft" | ""; /** * Initial open action. **/ export type OpenAction = { /** * Array with destination information. * dest[0] // internal pdf page reference. * dest[1] // contains destination view fit type name: * { name: 'XYZ' } - Destination specified as top-left corner point and a zoom factor (the lower-left corner of the page is the origin of the coordinate system (0, 0)). * { name: 'Fit' } - Fits the page into the window * { name: 'FitH' } - Fits the widths of the page into the window * { name: 'FitV' } - Fits the height of the page into a window. * { name: 'FitR' } - Fits the rectangle specified by its top-left and bottom-right corner points into the window. * { name: 'FitB' } - Fits the rectangle containing all visible elements on the page into the window. * { name: 'FitBH' } - Fits the width of the bounding box into the window. * { name: 'FitBV' } - Fits the height of the bounding box into the window. * dest[2] // x position offset * dest[3] // y position offset (note, the lower-left corner of the page is the origin of the coordinate system (0, 0)) * dest[4] // can be null, contains bounding box width when view name is FitR, * contains scale when view name is XYZ, * dest[5] // can be null, contains bounding box height when view name is FitR **/ dest: number[]; }; /** * Internal EventBus event name. **/ export type BusEventName = "outlineloaded" | "attachmentsloaded" | "namedaction" | "pagemode" | "fileattachmentannotation" | "pagerendered" | "pagecancelled" | "scalechange" | "pagesinit" | "pagesloaded" | "documentchanged" | "rotationchanging" | "updateviewarea" | "undostorechanged" | "annotationeditstarted" | "annotationeditdone" | "show-custom-layout" | "hide-custom-layout" | "client-area-pointerdown" | "selectannotation" | "unselectannotation" | "annotation-bounds-change" | "pagechange" | "mousemodechange" | "request-answer" | "textlayerready" | "textselectionchanged" | "viewersizechanged" | "articlebeadnavigate" | "error" | "open" | "pagelabels" | "documentload" | "add-replace-highlights" | "twofingerscrollstart" | "supportapi-document-opened" | "replytool-before-delete" | "replytool-before-scrollintoview" | "replytool-text-label-click" | "replytool-item-click" | "replytool-item-keydown" | "replytool-placeholder-activate" | "replytool-author-label-click" | "replytool-item-status-change" | "replytool-post-reply" | "keydown" | "keyup" | "before-open"; /** * Internal EventBus interface. **/ export interface IGCEventBus { /** * Listen event. **/ on(eventName: BusEventName, listener: Function): any; /** * Unlisten event. **/ off(eventName: BusEventName, listener: Function): any; /** * Internal listen implementation, takes priority over public "on" API. * @ignore **/ _on(eventName: BusEventName, listener: Function | false): any; /** * Internal unlisten implementation, takes priority over public "off" API. * @ignore **/ _off(eventName: BusEventName, listener: Function | false): any; /** * Raise event. **/ dispatch(eventName: BusEventName, ...rest: any[]): any; } /** * Built-in keyboard shortcut action tool name. **/ export type KeyboardShortcutTool = "zoomin" | "zoomout" | "zoom_pagesize" | "zoom_clientsize" | "select_all" | "rotate" | "pan" | "holdToPan" | "selection" | "open" | "search" | "print" | "move_caret_left" | "move_caret_right" | "move_caret_up" | "move_caret_down" | "move_caret_document_start" | "move_caret_document_end" | "move_caret_sequence_start" | "move_caret_sequence_end" | "confirm-ok" | "confirm-cancel" | "scrollUp" | "scrollDown" | "search" | "replace" | "undo" | "redo"; /** * Keyboard shortcut definition. **/ export type KeyboardShortcutDefinition = { /** * Optional key code. **/ keyCode?: number; /** * Specifies whether the Ctrl key should be pressed. **/ ctrl?: boolean; /** * Specifies whether the Shift key should be pressed. **/ shift?: boolean; /** * Specifies whether the Alt key should be pressed. **/ alt?: boolean; /** * Specifies whether the Meta key should be pressed. * @ignore exclude from docs until next release. **/ meta?: boolean; /** * Shortcut action. **/ tool?: KeyboardShortcutTool | Function; }; /** * Cancelable JS event arguments. **/ export type JsCancelEventArgs = { /** * Indicates whether the event should be canceled. **/ cancel?: boolean; /** * JS code which is executed. **/ jsCode: string; /** * Target annotation. * @ignore exclude from docs. **/ targetAnnotation: any; /** * JS executor worker. * @ignore exclude from docs. **/ executor: any; }; /** * JS event arguments. **/ export type JsEventArgs = { /** * JS code which is executed. **/ jsCode: string; /** * Target annotation. * @ignore exclude from docs. **/ targetAnnotation: any; /** * JS executor worker. * @ignore exclude from docs. **/ executor: any; }; /** * JavaScript execution configuration. **/ export type JsExecutionConfig = { /** * Set this setting to true if you want to permanently disable the JS action executor. **/ disable?: boolean; /** * Handler function which will be called before JS action execution started. * You can modify the args.jsCode property inside this handler function. * Set the args.cancel property to true if you wish to prevent further JS action execution; **/ before?: (args: JsCancelEventArgs) => void; /** * Handler function which will be called after JS action execution finished. **/ after?: (args: JsEventArgs) => void; /** * Redraw the active page after the JS action execution finished. * @default Default is false. * @ignore exclude from docs. DOC-5389 **/ repaintWhenDone?: boolean; /** * Redraw the active page on each asynchronous JS execution step. * @default Default is false. * @ignore exclude from docs. DOC-5389 **/ repaintOnStep?: boolean; }; /** * Document list item description. **/ export type DocumentListItem = { /** * Display name. **/ name: string; /** * Absolute or relative URL to a PDF document. **/ path: string; /** * Item tooltip. **/ title: string; /** * Optional. The HTML content to be used as the preview content in the document list. * If specified, this property will be used instead of the name property. **/ previewContent?: string; }; export type SubmitFormOptions = { /** * An array identifying which fields to include in the submission or which to exclude, depending on the setting of the include flag. **/ fields?: string[]; /** * Not used. * @ignore exclude from docs **/ refs?: string[]; /** * If true, the fields array specifies which fields to include in the submission. * If false, the fields array tells which fields to exclude. All fields in the document’s interactive form shall be submitted except those listed in the fields array. * If undefined, all fields will be included in the submission. **/ include?: boolean; /** * If set, all fields designated by the fields array and the include flag shall be submitted, regardless of whether they have a value. **/ includeNoValueFields?: boolean; /** * Meaningful only if the SubmitPDF and XFDF flags are clear. If set, field names and values shall be submitted in HTML Form format. If clear, they shall be submitted in Forms Data Format (FDF); see 12.7.8, "Forms data format". * @ignore exclude from docs **/ exportFormat?: boolean; /** * If set, field names and values shall be submitted using an HTTP GET request. * If clear, they shall be submitted using a POST request. **/ getMethod?: boolean; /** * If set, the coordinates of the mouse click that caused the submit-form action shall be transmitted as part of the form data. The coordinate values are relative to the upper-left corner of the field’s widget annotation rectangle. They shall be represented in the data in the format name . x = xval & name . y = yval where name is the field’s mapping name (TM in the field dictionary) if present; otherwise, name is the field name. If the value of the TM entry is a single ASCII SPACE (20h) character, both the name and the ASCII PERIOD (2Eh) following it shall be suppressed, resulting in the format x = xval & y = yval * This flag shall be used only when the ExportFormat flag is set. If ExportFormat is clear, this flag shall also be clear. * @ignore exclude from docs **/ submitCoordinates?: boolean; /** * Not used. * @ignore exclude from docs **/ submitUsingGet?: boolean; /** * (PDF 1.4) shall be used only if the SubmitPDF flags are clear. If set, field names and values shall be submitted as XFDF. * @ignore exclude from docs **/ xFDF?: boolean; /** * (PDF 1.4) If set, the document shall be submitted as PDF, using the MIME * (described in Internet RFC 2045, Multipurpose Internet Mail Extensions (MIME), * Part One: Format of Internet Message Bodies) content type application/pdf (as defined in RFC 8118). * If set, all other flags shall be ignored except GetMethod. * @ignore exclude from docs **/ submitPDF?: boolean; /** * (PDF 1.4) If set, any submitted field values representing dates shall be converted to the standard format described in 7.9.4, "Dates". * NOTE 1 The interpretation of a form field as a date is not specified explicitly in the field itself but only in the ECMAScript code that processes it. * @ignore exclude from docs **/ canonicalFormat?: boolean; }; /** * Options for scrolling the page into view, extending the DOM scroll options type. **/ export type ScrollPageIntoViewOptions = ScrollIntoViewOptions & { /** * Determines whether scrolling is instant or animates smoothly. * This option is a string which must take one of the following values: * - 'smooth': scrolling should animate smoothly * - 'instant': scrolling should happen instantly in a single jump * - 'auto': scroll behavior is determined by the computed value of scroll-behavior */ behavior?: ScrollBehavior; /** * Defines vertical alignment. One of start, center, end, or nearest. Defaults to start. */ block?: ScrollLogicalPosition; /** * Defines horizontal alignment. One of start, center, end, or nearest. Defaults to nearest. */ inline?: ScrollLogicalPosition; /** * Scroll mode property. Set to 'if-needed' if you don't want to scroll when the page is partially visible. * Defaults to 'if-needed'. */ scrollMode?: 'always' | 'if-needed'; /** * Sets the percentage of page visibility that triggers scrolling into view when the scrollMode property is set to 'if-needed'. */ visibilityThreshold?: number; }; /** * Data model for the TableDataExtraction feature. */ export type TableDataExtractionModel = { /** * The new text to be inserted. */ newText: string; /** * The text that will be replaced. */ selectedText: string; /** * Exact coordinates of the text to be replaced. */ selectedCoords: SelectedTextCoordinates; /** * Contains detailed information about font metrics and style. */ fontInfo: { /** * Font name. */ font: string; /** * Font height. */ fontHeight: number; /** * Font family. */ fontFamily: string | null; /** * Font descent distance. */ fontDescent: number; /** * Text scale. */ scale: number; }; }; /** * Data model for the ReplaceText feature. */ export type ReplaceTextModel = { /** * The new text to be inserted. */ newText: string; /** * The text that will be replaced. */ selectedText: string; /** * Exact coordinates of the text to be replaced. */ selectedCoords: SelectedTextCoordinates; /** * Contains detailed information about font metrics and style. */ fontInfo: { /** * Font name. */ font: string; /** * Font height. */ fontHeight: number; /** * Font family. */ fontFamily: string | null; /** * Font descent distance. */ fontDescent: number; /** * Text scale. */ scale: number; }; }; /** * Coordinates of the selected text. */ export type SelectedTextCoordinates = { /** * The index of the target page. */ pageIndex: number; /** * The outer rectangle bounding the selected text, represented as an array of numbers. */ outerRect: number[]; /** * The coordinates of the selected regions, represented as an array of arrays of points. * Each point is an object with `x` and `y` properties. */ quadPoints: { x: number; y: number; }[][]; }; /** * Specifies the font format. * * - `"truetype"`: TrueType Font (TTF). * - `"opentype"`: OpenType Font (OTF). * - `"woff"`: Web Open Font Format (WOFF). * - `"woff2"`: Web Open Font Format 2 (WOFF2). Not supported by the Wasm version of the SupportApi. * - `"ttc"`: TrueType Collection (TTC). This format is for fallback fonts only; see the {@link DsPdfViewer.registerFallbackFont} method for details. */ export type FontFormat = "truetype" | "opentype" | "woff" | "woff2" | "ttc";