@mescius/dspdfviewer
Version:
Document Solutions PDF Viewer
228 lines (227 loc) • 9.8 kB
TypeScript
import { AnnotationBase } from "../Annotations/AnnotationTypes";
import { ProgressDialogSink } from "../Dialogs/Types";
import { SaveSettings, StampCategory, ViewerFeatureName } from "../Models/ViewerTypes";
import { ClientTableExtractOptions } from "../TableDataExtraction/types";
import { LocalDocumentModification } from "./LocalDocumentModification";
import { OpenDocumentInfo, TableDefClientModel } from "./types";
/**
* The base SupportApi interface provides only those APIs that only make sense to the client
* (i.e., no multi-user support, no server-side stamps).
**/
export interface ISupportApiBase {
/**
* Unique identifier for the client viewer.
*/
clientId: string;
/**
* Information about the currently opened document, including meta-data.
*/
docInfo: OpenDocumentInfo;
/**
* Gets the ID of the currently opened document.
*/
documentId: string;
/**
* Indicates whether the current document is opened in shared mode (shared with other users).
*/
isDocumentShared: boolean;
/**
* Indicates whether the SupportApi client is currently connected to the server.
*/
isConnected: boolean;
/**
* Returns the type of the SupportApi implementation.
*/
supportApiType?: SupportApiType;
/**
* Applies the specified viewer options.
* @param {any} options - The new viewer options.
* @returns {void}
*/
applyOptions(options: any): void;
/**
* Sets the viewer instance for the SupportApi client. This method is called during the initialization of the viewer.
* It passes a reference to the viewer that utilizes an instance of the SupportApi client of this class.
*
* @param viewer The viewer instance that uses the SupportApi client instance of this class.
*/
setViewer(viewer: any): any;
/**
* Indicates whether the viewer has permission to edit the specified annotation.
* @param {AnnotationBase | null} annotation - The annotation to check for edit permissions.
* @returns {boolean} True if the viewer can edit the annotation; otherwise, false.
*/
canEditAnnotation(annotation?: AnnotationBase | null): boolean;
/**
* Ensure that the document loader exists on the server.
* Document Loader may not be present after a server restart.
* @returns A Promise that resolves to a boolean indicating whether the document loader is available.
*/
checkDocumentLoader(): Promise<boolean>;
cancelTask?(correlationId?: string): Promise<void> | undefined;
/**
* Checks the status of a long asynchronous task by its correlation ID.
*
* @param {string} [correlationId] - Optional correlation ID to identify the task.
* @returns {Promise<TaskStatusAnswer | null>} A promise that resolves to an object containing the task status, or null if an error occurs.
*/
checkTaskStatus?(correlationId?: string): Promise<TaskStatusAnswer | null>;
/**
* Closes the document loader and releases resources on the server.
* @returns A promise that resolves to a boolean indicating the success of the operation.
*/
closeDocumentLoader(): Promise<boolean>;
/**
* Closes previously opened document and free client and server resources.
*/
close(): Promise<string>;
/**
* Attempt to connect the SupportApi client to the server.
* @param lazy Optional. Set to true if you don't want to recheck the connection if the server has already been checked. Default is false.
* @returns A Promise that resolves to a boolean indicating whether the connection attempt was successful.
*/
connect(lazy?: boolean): Promise<boolean>;
/**
* Dispose SupportApi client.
*/
dispose(): any;
/**
* Returns an array of features that are disabled or unsupported by the SupportApi instance.
*
* @returns {ViewerFeatureName[] | null} - An array of feature names that are disabled/unsupported,
* or null if the information is unavailable.
*/
getDisabledFeatures(): ViewerFeatureName[] | null;
/**
* Gets the URL which can be used to download a modified document from the SupportApi service.
* @param filename The default value for the filename property in the HTTP header.
* @param format The format of the document to download ('PDF' or 'PNG').
* @param correlationId The correlation ID for tracking the request.
* @returns The URL for downloading the modified document.
*/
getDownloadUrl(filename: string, format: "PDF" | "PNG" | "SVG" | undefined, correlationId: string): Promise<string>;
/**
* Gets the URL which can be used to download an unmodified document from the SupportApi service.
* @param filename The default value for the filename property in the HTTP header.
* @returns The URL for downloading the unmodified document.
*/
getDownloadUnmodifiedUrl(filename: string): string;
/**
* Upload files.
* @param fileIds File identifiers to upload.
* @param sink Progress sink for tracking the upload progress.
* @returns A Promise that resolves to a boolean indicating the success of the upload.
*/
uploadFiles(fileIds: string[], sink?: ProgressDialogSink): Promise<boolean>;
/**
* Get the last operation error if there is one, or an empty string if there are no errors.
* */
getLastError(): Promise<string>;
/**
* Get predefined stamp images info.
* @returns A Promise that resolves to an array of StampCategory objects.
*/
getStampCategories(): Promise<StampCategory[]>;
/**
* Modifies an opened document and returns "ok" or an error message.
* @param {LocalDocumentModification} documentModification - The document modifications to apply.
* @param {string} correlationId - The correlation identifier for tracking the request.
* @returns {Promise<string>} A Promise that resolves to "ok" if the modification is successful, or an error message otherwise.
*/
modify(documentModification: LocalDocumentModification, correlationId: string): Promise<string>;
/**
* Open document using binary data.
* @param data
**/
openBinary(data: Uint8Array): Promise<void>;
/**
* Get Support API server version string.
**/
serverVersion(): Promise<string>;
/**
* Set viewer options.
* The method should be called before start using Support API or before saving changes.
* Returns "ok" or error message.
* @param saveSettings Save settings.
* @param correlationId Correlation identifier
* @param fileName File name
**/
setOptions(saveSettings: SaveSettings | undefined, correlationId: string, fileName?: string): Promise<string>;
/**
* Verify the signature field. Returns true if the document has not been modified since
* the signature field was applied, otherwise returns false.
*
* This method checks the integrity of the signature field by comparing the document's
* current state with the state at the time the signature was applied.
*
* @param {string} fieldName - The name of the signature field to be verified.
*
* @returns {Promise<boolean>} A promise that resolves to `true` if the document has not
* been modified since the signature was applied, and `false` otherwise.
*
* @example
* const isValid = await supportApi.verifySignature('signatureField1');
* console.log(isValid); // true or false
*/
verifySignature(fieldName: string): Promise<boolean>;
/**
* Extract table data from a document.
*
* This method extracts table data based on the provided settings, which include various options
* like precision and column width. If no settings are provided, default extraction settings are used.
*
* @param {ClientTableExtractOptions} [extractSettings] - The options for customizing the table extraction process.
*
* @returns {Promise<TableDefClientModel[] | null>} A promise that resolves to an array of
* `ExtractedTableData` objects if the extraction is successful, or `null` if no table data is found.
*
* @example
* const tables = await supportApi.extractTableData({ MinimumColWidth: 2 });
* console.log(tables); // Array of extracted tables or null
*/
extractTableData(extractSettings?: ClientTableExtractOptions): Promise<TableDefClientModel[] | null>;
}
/**
* Indicates the SupportApi implementation type.
*/
export type SupportApiType = "DsPdfWasm" | "WebApi" | "Custom";
/**
* Represents the status of a task.
*
* @typedef {Object} TaskStatusAnswer
* @property {ClientTaskType} taskType - The type of the task.
* @property {number} [current] - The current progress of the task.
* @property {number} [total] - The total progress of the task.
* @property {boolean} [done] - Indicates if the task is completed.
*/
export type TaskStatusAnswer = {
taskType: ClientTaskType;
current?: number;
total?: number;
done?: boolean;
};
/**
* Represents the type of client tasks.
*/
export declare enum ClientTaskType {
/**
* Unspecified task type.
*/
Unspecified = 0,
/**
* Task type for Save as PDF.
*/
Save = 1,
/**
* Common task type for Save as image.
*/
SaveAsImage = 2,
/**
* Task type for Save as PNG.
*/
SaveAsPng = 3,
/**
* Task type for Save as SVG.
*/
SaveAsSvg = 4
}