UNPKG

@syncfusion/ej2-pdf

Version:

Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.

231 lines (230 loc) 9.8 kB
import { PdfDocument } from './../pdf-document'; import { _PdfDictionary } from './../pdf-primitives'; import { _ExportHelper } from './xfdf-document'; import { PdfAnnotation } from './../annotations/annotation'; /** * Provides utilities to export and import FDF data for annotations and form fields and manages object mapping and serialization. * * @private */ export declare class _FdfDocument extends _ExportHelper { /** * Stores annotation objects collected during FDF export. * * Key and value types vary depending on annotation structure. * * @private */ _annotationObjects: Map<any, any>; /** * Special character set used to normalize or escape content during FDF processing. * * @private */ _specialCharacters: string; /** * Initializes the FDF export and import helper with an optional file name. * * @private * @param {string} fileName represent filename. */ constructor(fileName?: string); /** * Prepares and exports annotations from the document as an FDF byte array. * * @private * @param {PdfDocument} document Source PDF document to read annotations. * @returns {Uint8Array} Generated FDF payload containing exported annotations. */ _exportAnnotations(document: PdfDocument): Uint8Array; /** * Prepares and exports form fields from the document as an FDF byte array. * * @private * @param {PdfDocument} document Source PDF document to read form fields. * @returns {Uint8Array} Generated FDF payload containing exported form fields. */ _exportFormFields(document: PdfDocument): Uint8Array; /** * Finalizes FDF serialization and returns the composed byte array. * * @private * @returns {Uint8Array} Serialized FDF data representing the current export. */ _save(): Uint8Array; /** * Imports annotations from FDF bytes into the target PDF document. * * @private * @param {PdfDocument} document Target PDF document to receive annotations. * @param {Uint8Array} data Input FDF data containing annotations. * @returns {void} */ _importAnnotations(document: PdfDocument, data: Uint8Array): void; /** * Imports form field values from FDF bytes into the target PDF document. * * @private * @param {PdfDocument} document Target PDF document to receive form values. * @param {Uint8Array} data Input FDF data containing form field entries. * @returns {void} */ _importFormData(document: PdfDocument, data: Uint8Array): void; /** * Parses FDF content and fills internal tables for annotations or form values depending on mode. * * @private * @param {any} parser Parser used to iterate tokens and objects from FDF data. * @returns {void} */ _readFdfData(parser: any): void; /** * Recursively parses a dictionary and resolves nested structures and references. * * @private * @param {_PdfDictionary} dictionary Dictionary to parse and normalize. * @returns {void} */ _parseDictionary(dictionary: _PdfDictionary): void; /** * Resolves a specific dictionary entry and replaces references with concrete objects when available. * * @private * @param {_PdfDictionary} dictionary Dictionary holding the key to process. * @param {string} key Entry key to examine and resolve. * @returns {void} */ _parseDictionaryData(dictionary: _PdfDictionary, key: string): void; /** * Parses an array and resolves any contained references into usable objects. * * @private * @param {Array<any>} array Array to inspect and rewrite when necessary. * @returns {void} */ _parseArray(array: Array<any>): void; /** * Extracts annotation objects from parsed structures and removes trailer and root bookkeeping. * * @private * @returns {Map<any, any>} Map of annotation keys to their resolved dictionaries. */ _parseAnnotationData(): Map<any, any>; /** * Applies imported form values from the table to matching fields in the document form. * * @private * @returns {void} */ _importField(): void; /** * Iterates document pages and collects exportable annotations then writes FDF catalog and annots. * * @private * @param {PdfDocument} document Source document providing pages and annotations. * @param {number} pageCount Number of pages to process from the document. * @returns {void} */ _exportAnnotationData(document: PdfDocument, pageCount: number): void; /** * Serializes a single annotation and related objects into FDF objects updating indices and references. * * @private * @param {PdfAnnotation} annotation Annotation to export. * @param {string} fdfString Current FDF buffer for concatenation. * @param {number} index Current object index used for indirect references. * @param {string[]} annot Accumulator of annotation object ids. * @param {number} pageIndex Page index where the annotation resides. * @param {boolean} appearance Indicates whether appearance streams should be included. * @returns {_FdfHelper} Helper with updated index annotation ids and queued objects. */ _exportAnnotation(annotation: PdfAnnotation, fdfString: string, index: number, annot: string[], pageIndex: number, appearance: boolean): _FdfHelper; /** * Appends a stream section to the FDF output using content or compressed data as required. * * @private * @param {any} value Stream or stream holder to serialize. * @param {string} fdfString Current FDF buffer for concatenation. * @returns {void} */ _appendStream(value: any, fdfString: string): void; /** * Appends dictionary entries to FDF output and queues nested objects for subsequent emission while tracking streams. * * @private * @param {Map<any, any>} list Queue of pending objects keyed by assigned object id. * @param {number[]} streamReference List of object ids that must include a stream body. * @param {number} index Current object index used to allocate new ids. * @param {_PdfDictionary} dictionary Dictionary to serialize. * @param {string} fdfString Current FDF buffer for concatenation. * @param {boolean} hasAppearance Indicates whether appearance related entries are allowed. * @returns {_FdfHelper} Helper with updated list stream references and index. */ _getEntries(list: Map<any, any>, // eslint-disable-line streamReference: number[], index: number, dictionary: _PdfDictionary, fdfString: string, hasAppearance: boolean): _FdfHelper; /** * Appends an array to FDF output and captures indirect references for later emission. * * @private * @param {any[]} array Array to serialize. * @param {string} fdfString Current FDF buffer for concatenation. * @param {number} index Current object index used to allocate new ids. * @param {boolean} flag Marks whether contained references should be added to stream tracking. * @param {Map<any, any>} list Queue of pending objects keyed by assigned object id. * @param {number[]} streamReference List of object ids that must include a stream body. * @returns {_FdfHelper} Helper with updated list stream references and index. */ _appendArray(array: any[], // eslint-disable-line fdfString: string, index: number, flag: boolean, list: Map<any, any>, // eslint-disable-line streamReference: number[]): _FdfHelper; /** * Appends a single element to FDF output handling names numbers strings arrays dictionaries references and booleans. * * @private * @param {any} element Element to serialize. * @param {string} fdfString Current FDF buffer for concatenation. * @param {number} index Current object index used to allocate new ids. * @param {boolean} flag Marks whether references should be added to stream tracking. * @param {Map<any, any>} list Queue of pending objects keyed by assigned object id. * @param {number[]} streamReference List of object ids that must include a stream body. * @returns {_FdfHelper} Helper with updated list stream references and index. */ _appendElement(element: any, // eslint-disable-line fdfString: string, index: number, flag: boolean, list: Map<any, any>, // eslint-disable-line streamReference: number[]): _FdfHelper; /** * Escapes special characters in text for safe inclusion in FDF string literals. * * @private * @param {string} value Input text to sanitize for FDF output. * @returns {string} Text with escaped characters for FDF compatibility. */ _getFormattedString(value: string): string; /** * Validates FDF header and toggles specification mode based on special character markers. * * @private * @param {string} element Complete FDF text used to detect header and encoding markers. * @returns {void} */ _checkFdf(element: string): void; /** * Converts a text value to a hexadecimal string using PDF byte conversion rules. * * @private * @param {string} text Input text to convert into hex representation. * @returns {string} Hexadecimal string representing the input text. */ _stringToHexString(text: string): string; } /** * Holds intermediate data during FDF serialization including queued objects reference indices and annotation id list. * * @private */ export declare class _FdfHelper { list: Map<any, any>; streamReference: number[]; index: number; annot: string[]; }