UNPKG

@mescius/dspdfviewer

Version:
83 lines (82 loc) 3.78 kB
import { AnnotationBase } from "../Annotations/AnnotationTypes"; import GcPdfViewer from "../GcPdfViewer"; /** * Class to handle importing and exporting annotation data in XFDF format. * This class handles annotations and widget fields separately, supporting the export of PDF annotations and widget field data in the XFDF format. */ export declare class XFDFAnnotationHandler { viewer: GcPdfViewer; constructor(viewer: GcPdfViewer); /** * Exports annotations and widget field data to XFDF format. * Annotations are exported under the <annots> tag, and widget fields under the <fields> tag. * * @param filterFn Optional filter function to selectively export annotations or widget fields. * @returns A promise resolving to a string containing the XFDF representation of annotations and widget fields. */ exportAnnotationsToXFDF(filterFn?: (annotation: AnnotationBase) => boolean): Promise<string>; /** * Builds the <annots> section of the XFDF content. * This method converts annotation objects to their corresponding XFDF tags. * * @param annotations The array of annotations to convert. * @returns A string containing the <annots> section. */ private buildAnnotationsTag; /** * Builds the <fields> section of the XFDF content. * This method converts widget fields to their corresponding XFDF tags. * * @param widgetFields The array of widget field objects to convert. * @returns A string containing the <fields> section. */ private buildWidgetFieldsTag; /** * Converts an annotation object to XFDF format. * Handles converting annotation properties to the appropriate XFDF XML element. * * @param annotation The annotation object to convert to XFDF. * @returns A string representing the annotation in XFDF format. */ private annotationToXFDF; /** * Builds the <fields> section of the XFDF content. * This method converts widget fields to their corresponding XFDF tags. * * @param widgetFields The array of widget field objects to convert. * @returns A string containing the <fields> section. */ private widgetFieldToXFDF; /** * Returns the correct XFDF tag name based on the annotation type. * This method ensures the annotation type is correctly mapped to XFDF-compatible tags. * * @param annotationType The annotation type to convert to XFDF tag name. * @returns The corresponding XFDF tag name. */ private getAnnotationTypeName; /** * Imports annotation data from XFDF format. * Parses the XFDF XML data, converts each annotation element back to an annotation object. * * @param xfdfString The XFDF string containing annotation data to import. * @param filterFn Optional filter function to selectively import annotations or widget fields. * @returns An array of imported annotations. */ importAnnotationsFromXFDF(xfdfString: string, filterFn?: (annotation: AnnotationBase) => boolean): AnnotationBase[]; /** * Converts an XFDF annotation element into an annotation object. * Extracts the attributes from the XFDF element and maps them to annotation object properties. * * @param element The XFDF element representing an annotation. * @returns The corresponding annotation object. */ private annotationFromXFDF; /** * Converts an XFDF widget field element into a widget field object. * * @param element The XFDF field element representing a widget field. * @returns The corresponding widget field object. */ private widgetFieldFromXFDF; }