import { _MatrixHelper, _TransformationStack } from './text-extraction/matrix-helper'; import { TextGlyph, TextLine, TextWord } from './text-structure'; import { _PdfContentParserHelper } from './content-parser-helper'; import { _GraphicState } from './graphic-state'; import { _FontStructure } from './text-extraction/font-structure'; import { canvasRenderCallback } from './utils'; import { PdfDocument, _PdfDictionary, _PdfReference, PdfPage, _PdfRecord, _PdfCrossReference, PdfFontStyle, Rectangle } from '@syncfusion/ej2-pdf'; import { _PdfTextParser } from './pdf-text-parser'; import { PdfStructureElement } from './pdf-structure-element'; import { PdfEmbeddedImage } from './image-extraction/pdf-embedded-image'; /** * Represents the text search result. */ export declare type TextSearchResult = { /** * The text to search for in the PDF document. */ searchText: string; /** * A Map where keys are 1-based page numbers and values are arrays of bounding rectangles for matches on that page. */ searchResults: Map; }; /** * Represents the text search options. */ export declare type TextSearchOptions = { caseSensitive?: boolean; wholeWord?: boolean; startPageIndex?: number; endPageIndex?: number; }; /** * Represents a utility for extracting data from a PDF document. * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract `TextLine` from the PDF document. * let textLines: Array = extractor.extractTextLinesSync({ startPageIndex: 0, endPageIndex: document.pageCount-1}); * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` */ export declare class PdfDataExtractor { /** The PDF document being processed. * * @private */ _document: PdfDocument; /** Current page rotation being processed. * * @private */ _rotation: number; /** Current text matrix for rendering calculations. * * @private */ _textMatrix: _MatrixHelper; /** Current text leading value. * * @private */ _textLeading: number; /** Current text color as RGB array. * * @private */ _textColor: number[]; /** Current text line matrix. * * @private */ _textLineMatrix: _MatrixHelper; /** Buffer for the currently extracted text fragment. * * @private */ _extractedText: string; /** Flag indicating a recent leading operation. * * @private */ _hasLeading: boolean; /** Flag indicating absence of spacing between fragments. * * @private */ _hasNoSpacing: boolean; /** Collected text lines when extracting layout. * * @private */ _textLines: TextLine[]; /** Stack of transformation matrices used during rendering. * * @private */ _transformations: _TransformationStack; /** Identity matrix helper. * * @private */ _identityMatrix: number[]; /** Current text cursor location [x,y]. * * @private */ _currentLocation: number[]; /** Current font name used for extraction. * * @private */ _currentFont: string; /** Temporary bounding rectangle used while computing word/line bounds. * * @private */ _tempBoundingRectangle: Rectangle; /** Current bounding rectangle for the most recent glyph. * * @private */ _boundingRectangle: Rectangle; /** Previous glyph bounding rectangle. * * @private */ _previousRect: Rectangle; /** Current font size in use. * * @private */ _fontSize: number; /** Horizontal text scaling (percentage). * * @private */ _textHorizontalScaling: number; /** Previous text matrix snapshot. * * @private */ _previousTextMatrix: _MatrixHelper; /** Previous font size encountered. * * @private */ _previousFontSize: number; /** Previously extracted text fragment. * * @private */ _previousExtractText: string; /** Vertical text rise applied to glyphs. * * @private */ _arise: number; /** Flag indicating whether current matrix is text matrix. * * @private */ _isTextMatrix: boolean; /** Current text matrix used for comparisons. * * @private */ _currentTextMatrix: _MatrixHelper; /** Aggregated text buffer for multi-operator sequences. * * @private */ _text: string; /** Flag indicating a recent TJ operator was processed. * * @private */ _hasTj: boolean; /** Flag indicating a recent Tm operator was processed. * * @private */ _hasTm: boolean; /** Flag indicating a recent ET operator (end text) was processed. * * @private */ _hasET: boolean; /** Character spacing value. * * @private */ _characterSpacing: number; /** Word spacing value. * * @private */ _wordSpacing: number; /** Flag indicating a marked content block has begun. * * @private */ _hasBeginMarkedContent: boolean; /** Temporary x-difference used for spacing heuristics. * * @private */ _differenceX: number; /** Internal text scale factor. * * @private */ _textScale: number; /** Internal text rise value. * * @private */ _textRise: number; /** Accumulated width for word bounds. * * @private */ _width: number; /** Accumulated height for word bounds. * * @private */ _height: number; /** PDF cross-reference for object resolution. * * @private */ _crossReference: _PdfCrossReference; /** Resultant extracted text for the document. * * @private */ _resultantText: string; /** Currently extracted fragment for the active operator. * * @private */ _currentExtractedText: string; /** Initial transform applied to page content during extraction. * * @private */ _initialTransForm: _MatrixHelper; /** Accumulated glyphs for the current word. * * @private */ _textGlyph: TextGlyph[]; /** Collected words for the current line. * * @private */ _textWord: TextWord[]; /** Collected text lines for extraction. * * @private */ _textLine: TextLine[]; /** Array of extracted text fragments. * * @private */ _textExtraction: string[]; /** Cache of font structures keyed by resource name. * * @private */ _fontCollection: Map; /** Current CTM (current transformation matrix). * * @private */ _ctm: _MatrixHelper; /** Stack of object matrices pushed by graphics state. * * @private */ _objects: _MatrixHelper[]; /** Flag toggling layout-aware extraction. * * @private */ _isLayout: boolean; /** Flag indicating the page is rotated. * * @private */ _isRotatePage: boolean; /** Flag for extracting text lines instead of plain text. * * @private */ _isExtractTextLines: boolean; /** Content parser helper instance. * * @private */ _contentParser: _PdfContentParserHelper; /** Internal text parser utility. * * @private */ _parser: _PdfTextParser; /** Root structure element for tagged PDF extraction. * * @private */ _structureElement: PdfStructureElement; /** Collection of PDF references encountered. * * @private */ _referenceCollection: _PdfReference[]; /** Order counter used when building structure tree. * * @private */ _elementOrder: number; /** Cached page-level structure elements. * * @private */ _pageElements: PdfStructureElement[]; /** All discovered structure elements in the document. * * @private */ _elementCollection: PdfStructureElement[]; /** Set used to deduplicate element order indices. * * @private */ _orderSet: Set; /** Map of MCID to collected text fragments. * * @private */ _mcidTextMap: Map; /** Flag indicating extraction of tagged text is enabled. * * @private */ _extractTaggedText: boolean; /** Current marked content id during parsing. * * @private */ _currentContentId: number; /** Map of element bounds keyed by id arrays. * * @private */ _elementBoundsMap: Map; /** Flag indicating the document has content IDs. * * @private */ _hasContentID: boolean; /** Collection of embedded images discovered. * * @private */ _imageInfo: PdfEmbeddedImage[]; /** Optional canvas provider used for image extraction. * * @private */ _canvas: any; /** * Initialize a new instance of the `PdfDataExtractor` class * * @param {PdfDocument} document PDF document to get pages * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract collection of `PdfEmbeddedImage` from the PDF document. * let imageInfoCollection: PdfEmbeddedImage[] = extractor.extractImages({ startPageIndex: 0, endPageIndex: document.pageCount - 1}); * let imageInfo: PdfEmbeddedImage = imageInfoCollection[0]; * let data: Uint8Array = imageInfo.data; * // Destroy the documents * document.destroy(); * ``` */ constructor(document: PdfDocument); /** * Initialize a new instance of the `PdfDataExtractor` class * * @param {PdfDocument} document PDF document to get pages * @param {Function} callBack - A callback function that returns a canvas element for rendering. * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data); * // Define a canvas render callback that returns a canvas element and the application platform. * const canvasRenderCallback = (): {canvas: any, applicationPlatform: ApplicationPlatform} => { * const canvas = document.createElement('canvas'); * return { canvas: canvas, applicationPlatform: ApplicationPlatform.typescript }; * }; * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document, callBack: canvasRenderCallback); * // Extract collection of `PdfEmbeddedImage` from the PDF document. * let imageInfoCollection: PdfEmbeddedImage[] = extractor.extractImages({ startPageIndex: 0, endPageIndex: document.pageCount - 1}); * let imageInfo: PdfEmbeddedImage = imageInfoCollection[0]; * let data: Uint8Array = imageInfo.data; * // Destroy the documents * document.destroy(); * ``` */ constructor(document: PdfDocument, callBack: canvasRenderCallback); /** * Extract text from the PDF document, synchronously. * * @returns {string} The extracted text * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data1); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract text content from the PDF document. * let text: string = extractor.extractTextSync(); * // Save the output PDF * document.save(‘Output.pdf’); * // Destroy the documents * document.destroy(); * ``` */ extractTextSync(): string; /** * Extract text from a specified page range in the PDF document with optional layout preservation, synchronously. * * @param {object} options Options to specify the page range to be selected and to extract the text. * @returns {string} The extracted text * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data1); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract text content from the PDF document. * let text: string = extractor.extractTextSync({ startPageIndex: 0, endPageIndex: document.pageCount - 1 }); * // Save the output PDF * document.save(‘Output.pdf’); * // Destroy the documents * document.destroy(); * ``` */ extractTextSync(options: { isLayout?: boolean; startPageIndex?: number; endPageIndex?: number; }): string; /** * Extract text from the PDF document. * * @returns {Promise} The extracted text * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data1); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract text content from the PDF document. * let text: string = await extractor.extractText(); * // Save the output PDF * document.save('Output.pdf'); * // Destroy the documents * document.destroy(); * ``` */ extractText(): Promise; /** * Extract text from a specified page range in the PDF document with optional layout preservation. * * @param {object} options Options to specify the page range to be selected and to extract the text. * @returns {Promise} The extracted text * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data1); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract text content from the PDF document. * let text: string = await extractor.extractText({ startPageIndex: 0, endPageIndex: document.pageCount - 1 }); * // Save the output PDF * document.save('Output.pdf'); * // Destroy the documents * document.destroy(); * ``` */ extractText(options: { isLayout?: boolean; startPageIndex?: number; endPageIndex?: number; }): Promise; /** Render text in layout mode for a page record collection. * * @private * @param {_PdfRecord[]} recordCollection - Parsed content stream records for the page. * @param {PdfPage} page - Page being processed. * @param {Map} fontCollection - Fonts resolved for the page. * @param {Map} xObjectCollection - XObject resources for the page. * @returns {any} returns layout parameter. */ _renderTextAsLayOut(recordCollection: _PdfRecord[], page: PdfPage, fontCollection: Map, xObjectCollection: Map): any; /** Render text in layout mode for a page record collection. * * @private * @param {_PdfRecord[]} recordCollection - Parsed content stream records for the page. * @param {PdfPage} page - Page being processed. * @param {Map} fontCollection - Fonts resolved for the page. * @param {Map} xObjectCollection - XObject resources for the page. * @returns {any} returns layout parameter. */ _renderPdfTextAsLayOut(recordCollection: _PdfRecord[], page: PdfPage, fontCollection: Map, xObjectCollection: Map): Promise; /** Render page text using parsed records and the given graphic state. * * @private * @param {PdfPage} page - Page to process. * @param {Map} fontCollection - Font resources for page. * @param {Map} xObjectCollection - XObject resources for page. * @param {_GraphicState} graphicState - Current graphics/text state. * @param {boolean} [imageExtraction] - Whether called for image extraction. * @returns {any} values from rendering text */ _renderText(page: PdfPage, fontCollection: Map, xObjectCollection: Map, graphicState: _GraphicState, imageExtraction?: boolean): any; /** Render page text using parsed records and the given graphic state. * * @private * @param {PdfPage} page - Page to process. * @param {Map} fontCollection - Font resources for page. * @param {Map} xObjectCollection - XObject resources for page. * @param {_GraphicState} graphicState - Current graphics/text state. * @param {boolean} [imageExtraction] - Whether called for image extraction. * @returns {any} values from rendering text */ _renderPdfText(page: PdfPage, fontCollection: Map, xObjectCollection: Map, graphicState: _GraphicState, imageExtraction?: boolean): Promise; /** Extract image collection from a page's parsed record collection. * * @private * @param {PdfPage} page - Page to extract images from. * @param {Map} fontCollection - Font resources available. * @param {Map} xObjectCollection - XObject resources to resolve images. * @param {_GraphicState} graphicState - Graphics/text state for extraction. * @returns {Promise} Resolves when image extraction completes. */ _extractImagcollection(page: PdfPage, fontCollection: Map, xObjectCollection: Map, graphicState: _GraphicState): Promise; /** Set the text leading (TL operator) for subsequent line moves. * * @private * @param {number} textLeading - Leading value to set. * @returns {void} */ _setTextLeading(textLeading: number): void; /** Move the text position to the next line by applying a translation. * * @private * @param {number} tx - Translation in x. * @param {number} ty - Translation in y. * @param {_MatrixHelper} textLineMatrix - Current text line matrix. * @returns {void} */ _moveToNextLine(tx: number, ty: number, textLineMatrix: _MatrixHelper): void; /** Update the internal text matrix based on a TJ adjustment. * * @private * @param {number} tj - Adjustment value from TJ array. * @returns {_MatrixHelper} Updated text line matrix. */ _updateTextMatrix(tj: number): _MatrixHelper; /** Advance the internal text line matrix after a character is placed. * * @private * @param {string} char - Character drawn. * @param {number} width - Character width used for advance. * @returns {void} */ _updateTextLineMatrix(char: string, width: number): void; /** Decode and render a TJ/Tj element into an extracted string. * * @private * @param {string[]} elements - Encoded element operands. * @param {PdfPage} page - Page used to compute transforms/metrics. * @param {Map} fontCollection - Font structures available. * @returns {string} The extracted string content. */ _renderTextElementFromTJ(elements: string[], page: PdfPage, fontCollection: Map): string; /** Calculate the visual height of text given font metrics and matrices. * * @private * @param {_FontStructure} font - Font metadata used for height calculation. * @param {_MatrixHelper} textMatrix - The text rendering matrix. * @returns {number} Computed height in device units. */ _getTextHeight(font: _FontStructure, textMatrix: _MatrixHelper): number; /** Multiply two affine matrices represented as [a,b,c,d,e,f]. * * @private * @param {number[]} m1 - Left matrix in affine form. * @param {number[]} m2 - Right matrix in affine form. * @returns {number[]} Resulting product matrix. */ _transform(m1: number[], m2: number[]): number[]; /** Build internal TextLine/TextWord structures when rendering rotated text streams. * * @private * @param {string[]} elements - Encoded text operands. * @param {PdfPage} page - Page context for the glyphs. * @param {Map} fontCollection - Fonts available. * @returns {void} */ _buildTextContentStream(elements: string[], page: PdfPage, fontCollection: Map): void; /** Compute text width and update glyph/word state for a sequence. * * @private * @param {string} text - Text to measure. * @param {number} extraSpacing - Extra spacing applied to the last glyph. * @param {_FontStructure} currentFont - Font used for measurement. * @param {PdfPage} page - Page used for context/rotation. * @param {string} tempString - Current accumulating word string. * @returns {string} Updated accumulating word string. */ _getTextWidth(text: string, extraSpacing: number, currentFont: _FontStructure, page: PdfPage, tempString: string): string; /** Create and split words/glyphs into TextGlyph/TextWord objects. * * @private * @param {string} glyph - Single glyph character. * @param {string} tempString - Accumulating word buffer. * @param {string} fontName - Font name to assign to glyphs. * @param {PdfFontStyle} fontStyle - Font style to assign to glyphs. * @param {PdfPage} page - Page context for rotation and bounds. * @param {number} [rotation] - Optional rotation hint. * @param {number[]} [textColor] - Optional RGB color for glyph. * @returns {string} Updated temporary word string. */ _splitWords(glyph: string, tempString: string, fontName: string, fontStyle: PdfFontStyle, page: PdfPage, rotation?: number, textColor?: number[]): string; /** Build the text rendering matrix combining font size, Tm/Tlm and CTM. * * @private * @returns {_MatrixHelper} The text rendering matrix. */ _getTextRenderingMatrix(): _MatrixHelper; /** Parse and apply the Tf operator (font and size). * * @private * @param {string[]} fontElements - Operands passed to Tf. * @returns {void} */ _renderFont(fontElements: string[]): void; /** * Extract `TextLine` collection from all pages of the PDF document, synchronously. * * @returns {TextLine[]} The extracted textLines * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data1); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract `TextLine` from the PDF document. * let textCollection: TextLine[] = extractor.extractTextLinesSync(); * // Save the output PDF * document.save(‘Output.pdf’); * // Destroy the documents * document.destroy(); * ``` */ extractTextLinesSync(): TextLine[]; /** * Extract `TextLine` collection from all pages of the PDF document, synchronously * * @param {object} options The options to specify the page range to be selected. * @returns {TextLine[]} The extracted textLines * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data1); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract `TextLine` from the PDF document. * let textCollection: TextLine[] = extractor.extractTextLinesSync({ startPageIndex: 0, endPageIndex: document.pageCount - 1}); * // Save the output PDF * document.save(‘Output.pdf’); * // Destroy the documents * document.destroy(); * ``` */ extractTextLinesSync(options: { startPageIndex?: number; endPageIndex?: number; }): TextLine[]; /** * Extract `TextLine` collection from all pages of the PDF document. * * @returns {Promise} The extracted textLines * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data1); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract `TextLine` from the PDF document. * let textCollection: TextLine[] = await extractor.extractTextLines(); * // Save the output PDF * document.save('Output.pdf'); * // Destroy the documents * document.destroy(); * ``` */ extractTextLines(): Promise; /** * Extract `TextLine` collection from all pages of the PDF document. * * @param {object} options The options to specify the page range to be selected. * @returns {Promise} The extracted textLines * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data1); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract `TextLine` from the PDF document. * let textCollection: TextLine[] = await extractor.extractTextLines({ startPageIndex: 0, endPageIndex: document.pageCount - 1 }); * // Save the output PDF * document.save('Output.pdf'); * // Destroy the documents * document.destroy(); * ``` */ extractTextLines(options: { startPageIndex?: number; endPageIndex?: number; }): Promise; /** * //Extract all image information from the PDF document * * @returns {Promise} The extracted collection of image information * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract collection of `PdfEmbeddedImage` from the PDF document. * let imageInfoCollection: PdfEmbeddedImage[] = extractor.extractImages({ startPageIndex: 0, endPageIndex: document.pageCount - 1}); * let imageInfo: PdfEmbeddedImage = imageInfoCollection[0]; * let data: Uint8Array = imageInfo.data; * // Destroy the documents * document.destroy(); * ``` */ extractImages(): Promise; /** * Extract all image information from the PDF document * * @param {object} options The options to specify the page range to be selected. * @returns {Promise} The extracted collection of image information * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Extract collection of `PdfEmbeddedImage` from the PDF document. * let imageInfoCollection: PdfEmbeddedImage[] = extractor.extractImages({ startPageIndex: 0, endPageIndex: document.pageCount - 1}); * let imageInfo: PdfEmbeddedImage = imageInfoCollection[0]; * let data: Uint8Array = imageInfo.data; * // Destroy the documents * document.destroy(); * ``` */ extractImages(options: { startPageIndex?: number; endPageIndex?: number; }): Promise; /** * Searches for text in the PDF document and returns the bounding rectangles * of all matches grouped by page number, synchronously. * * @param {string} searchText The text to search for in the PDF document. * @param {TextSearchOptions} options The text search options. * @returns {TextSearchResult} The text search result. * * ```typescript * // Load an existing PDF document. * const document: PdfDocument = new PdfDocument(data); * // Initialize a new instance of the PdfDataExtractor class. * const extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Search for text within the specified page range. * const result: TextSearchResult = extractor.findTextSync('text', { * caseSensitive: false, * wholeWord: true, * startPageIndex: 2, * endPageIndex: 3 * }); * * // Get the searched text. * const searchText: string = result.searchText; * // The map keys are one-based page numbers, and the values are * // collections of bounding rectangles for the matches on each page. * const searchResults: Map = result.searchResults; * // Destroy the document. * document.destroy(); * ``` */ findTextSync(searchText: string, options?: TextSearchOptions): TextSearchResult; /** * Searches for a text collection in the PDF document and returns the text * search results that specify the bounding rectangles of all matches * grouped by page number, synchronously. * * @param {string[]} searchText The collection of text values to search for * in the PDF document. * @param {TextSearchOptions} options The text search options. * @returns {TextSearchResult[]} The text search results. * * ```typescript * // Load an existing PDF document. * const document: PdfDocument = new PdfDocument(data); * // Initialize a new instance of the PdfDataExtractor class. * const extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Search for multiple text values within the specified page range. * const results: TextSearchResult[] = extractor.findTextSync( * ['text', 'PDF'], * { * caseSensitive: false, * wholeWord: true, * startPageIndex: 2, * endPageIndex: 3 * } * ); * // Access the first text search result. * const result: TextSearchResult = results[0]; * // Get the searched text. * const searchText: string = result.searchText; * // The map keys are one-based page numbers, and the values are * // collections of bounding rectangles for the matches on each page. * const searchResults: Map = result.searchResults; * // Destroy the document. * document.destroy(); * ``` */ findTextSync(searchText: string[], options?: TextSearchOptions): TextSearchResult[]; /** * Rebuilds the plain-text extraction result in logical RTL reading order. * Non-RTL documents keep the existing flat text. RTL documents are rebuilt * from the line pipeline so rows are read top-to-bottom and RTL rows are * emitted right-to-left, matching Adobe extraction order. * * @private * @param {number} startIndex - Start page index of the extraction. * @param {number} endIndex - End page index of the extraction. * @param {string} flatText - Flat extracted text in stream order. * @returns {string} Reading-order text for RTL documents, otherwise flatText. */ private _buildRtlReadingText; /** * Asynchronous variant of `_buildRtlReadingText`. * * @private * @param {number} startIndex - Start page index of the extraction. * @param {number} endIndex - End page index of the extraction. * @param {string} flatText - Flat extracted text in stream order. * @returns {Promise} Reading-order text for RTL documents, otherwise flatText. */ private _buildRtlReadingTextAsync; private _normalizeTextLines; /** * Computes the vertical tolerance used to decide whether two text lines * share the same baseline (fraction of the dominant line height). * * @private * @param {TextLine[]} textLines - Lines being merged. * @returns {number} Row-grouping tolerance in page units. */ private _getMergeRowTolerance; /** * Determines whether two line bounds share the same baseline row. * * @private * @param {Rectangle} first - First line bounds. * @param {Rectangle} second - Second line bounds. * @param {number} tolerance - Vertical tolerance for row grouping. * @returns {boolean} True when both lines are on the same baseline row. */ private _isSameRtlRowLine; /** * Determines whether the horizontal gap between two same-baseline lines is * small enough to treat them as words of the same visual line. Large gaps * (columns, tab-separated figures) are kept as separate lines. * * @private * @param {Rectangle} previous - Bounds of the already merged line. * @param {Rectangle} current - Bounds of the candidate line to merge. * @param {number} tolerance - Row tolerance used as the gap scale. * @returns {boolean} True when the gap indicates words of one visual line. */ private _isAdjacentWordGap; /** * Computes the union of two line bounds. * * @private * @param {Rectangle} first - First line bounds. * @param {Rectangle} second - Second line bounds. * @returns {Rectangle} Union bounds covering both lines. */ private _getMergedBounds; /** * Normalizes a single text line (and its words) from visual RTL order into * logical reading order, sorting RTL words right-to-left by position when * the line advances leftward. * * @private * @param {TextLine} textLine - Line to normalize. * @returns {void} */ private _normalizeRtlTextLine; /** * Determines whether the words of a line advance leftward (visual RTL order) * by comparing the bounds of consecutive words. * * @private * @param {TextWord[]} words - Line words in stream order. * @returns {boolean} True when consecutive words are placed right-to-left. */ private _isLineAdvancingLeftward; /** * Coordinates document-wide text search and returns the search results for all supplied search strings. * * @private * @param {string[]} searchTextCollection The collection of search text. * @param {TextSearchOptions} options The resolved text search options. * @returns {TextSearchResult[]} The text search results. */ private _findTextMatches; /** * Searches for multiple text values on a single page using existing extracted text structures. * * @private * @param {number} pageIndex The zero-based page index to search. * @param {TextLine[]} pageLines The text lines extracted from the page. * @param {string[]} searchTextCollection The collection of search text. * @param {TextSearchOptions} options The text search options. * @returns {Map} Match bounds grouped by search-text index. */ private _findTextMatchesInPage; /** * Converts extracted text bounds into page annotation coordinate bounds. * * @private * @param {PdfPage} page The page that contains the matched text. * @param {Rectangle} bounds The extracted text word bounds. * @returns {Rectangle} The find text bounds in annotation coordinate space. */ private _getFindTextBounds; /** * Searches for text in the PDF document and returns the bounding rectangles * of all matches grouped by page number. * * @param {string} searchText - The text to search for in the PDF document. * @param {TextSearchOptions} options - The text search options. * @returns {Promise} The text search result. * * ```typescript * // Load an existing PDF document. * const document: PdfDocument = new PdfDocument(data); * // Initialize a new instance of the PdfDataExtractor class. * const extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Search for text within the specified page range. * const result: TextSearchResult = await extractor.findText('text', { * caseSensitive: false, * wholeWord: true, * startPageIndex: 2, * endPageIndex: 3 * }); * // Get the searched text. * const searchText: string = result.searchText; * // The map keys are one-based page numbers, and the values are * // collections of bounding rectangles for the matches on each page. * const searchResults: Map = result.searchResults; * // Destroy the document. * document.destroy(); * ``` */ findText(searchText: string, options?: TextSearchOptions): Promise; /** * Searches for a collection of text values in the PDF document and returns * the bounding rectangles of all matches grouped by page number. * * @param {string[]} searchText - The collection of text values to search for * in the PDF document. * @param {TextSearchOptions} options - The text search options. * @returns {Promise} The text search results. * * @example * ```typescript * // Load an existing PDF document. * const document: PdfDocument = new PdfDocument(data); * // Initialize a new instance of the PdfDataExtractor class. * const extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Search for multiple text values within the specified page range. * const results: TextSearchResult[] = await extractor.findText( * ['text', 'PDF'], * { * caseSensitive: false, * wholeWord: true, * startPageIndex: 2, * endPageIndex: 3 * } * ); * // Access the first text search result. * const result: TextSearchResult = results[0]; * const searchText: string = result.searchText; * // The map keys are one-based page numbers, and the values are * // collections of bounding rectangles for the matches on each page. * const searchResults: Map = result.searchResults; * // Destroy the document. * document.destroy(); * ``` */ findText(searchText: string[], options?: TextSearchOptions): Promise; /** * Coordinates document-wide asynchronous text search and returns the * search results for all supplied search strings. * * Text lines are extracted only once for the requested page range. * * @private * @param {string[]} searchTextCollection The collection of search text. * @param {TextSearchOptions} options The resolved text search options. * @returns {Promise} The text search results. */ private _findTextMatchesAsync; /** * Applies inverse page rotation to a point. * * @private * @param {PdfPage} page The page that contains the point. * @param {number} x The x-coordinate. * @param {number} y The y-coordinate. * @returns {number[]} The transformed point. */ private _transformFindTextPoint; /** * Creates rectangle bounds from transformed points. * * @private * @param {number} points The transformed points. * @returns {Rectangle} The bounds that include all points. */ private _getFindTextBoundsFromPoints; /** * Normalizes rectangle bounds to positive width and height. * * @private * @param {Rectangle} bounds The bounds to normalize. * @returns {Rectangle} The normalized bounds. */ private _normalizeFindTextBounds; /** Process page range and perform text/image extraction per page. * * @private * @param {number} startIndex - First page index to process. * @param {number} endIndex - Last page index to process. * @param {boolean} [isImageExtraction] - When true, run image extraction flow. * @returns {void} */ _processPages(startIndex: number, endIndex: number, isImageExtraction?: boolean): void; _processPdfPages(startIndex: number, endIndex: number, isImageExtraction?: boolean): Promise; /** * Gets the root structure element of the PDF document. * * @returns {PdfStructureElement} The root structure element of the PDF document. * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Access the structure element of the PDF document * let rootStructureElement: PdfStructureElement = extractor.getStructureElement(); * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` */ getStructureElement(): PdfStructureElement; /** * Gets the structure elements of PDF page. * * @param {PdfPage} page PDF page * @returns {PdfStructureElement[]} Structure elements * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Initialize a new instance of the `PdfDataExtractor` class * let extractor: PdfDataExtractor = new PdfDataExtractor(document); * // Retrieve structure elements from the first page * let page: PdfPage = document.getPage(0); * let structureElements: PdfStructureElement[] = extractor.getStructureElements(page); * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` */ getStructureElements(page: PdfPage): PdfStructureElement[]; /** Collect structure elements that belong to a given page recursively. * * @private * @param {PdfStructureElement} element - Structure element to traverse. * @param {PdfPage} page - Page whose elements should be collected. * @returns {void} */ _getPageElements(element: PdfStructureElement, page: PdfPage): void; /** Retrieve the document's StructTreeRoot and build the structure tree. * * @private * @returns {PdfStructureElement} Root structure element or undefined. */ _getStructureTreeRoot(): PdfStructureElement; /** Load a structure element from a dictionary and recursively its children. * * @private * @param {_PdfDictionary} structureDictionary - Dictionary representing the element. * @param {PdfStructureElement} [parent] - Optional parent element. * @returns {PdfStructureElement} Loaded structure element. */ _getStructureElement(structureDictionary: _PdfDictionary, parent?: PdfStructureElement): PdfStructureElement; /** Determine whether the StructTreeRoot contains a single top-level element. * * @private * @param {_PdfDictionary} treeRoot - The StructTreeRoot dictionary. * @returns {boolean} True when a single root element is present. */ _isSingleRootElement(treeRoot: _PdfDictionary): boolean; /** Compute bounds for a figure element by scanning page content streams. * * @private * @param {PdfStructureElement} structElement - Structure element representing the figure. * @param {PdfPage} page - Page containing the figure. * @returns {Rectangle} Computed element bounds. */ _getFigureBounds(structElement: PdfStructureElement, page: PdfPage): Rectangle; }