import { _PdfContentStream, _PdfCrossReference, _PdfRecord, PdfDocument, PdfPage, Rectangle } from '@syncfusion/ej2-pdf'; import { TextGlyph } from '../text-structure'; import { _PdfContentParserHelper } from '../content-parser-helper'; import { canvasRenderCallback } from '../utils'; import { _TextGlyphMapper } from './text-glyph-mapper'; import { _PdfRedactionProcessor } from './pdf-redaction-processor'; import { PdfRedactionRegion } from './pdf-redaction-region'; /** * Represents a content redactor from an existing PDF document. * * ```typescript * let document: PdfDocument = new PdfDocument(data, password); * // Create a new text extractor * let redactor: PdfRedactor = new PdfRedactor(document); * // Add redactions to the collection * let redactions: PdfRedactionRegion[] = []; * redactions.push(new PdfRedactionRegion(0, {x: 10, y: 10, width: 100, height: 50})); * redactions.push(new PdfRedactionRegion(2, {x: 10, y: 10, width: 100, height: 50}, true, {r: 255, g: 0, b: 0})); * redactor.add(redactions); * // Apply redactions on the PDF document * redactor.redactSync(); * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` */ export declare class PdfRedactor { /** * The loaded PDF document being redacted. * * @private */ _document: PdfDocument; /** * Internal flag indicating hex-string context during text replacement. * * @private */ _isHex: boolean; /** * Accumulated redaction regions for the current page batch. * * @private */ _redactionRegion: PdfRedactionRegion[]; /** * Page-indexed map of pending redaction regions. * * @private */ _redaction: Map; /** * Internal content parser helper configured for redaction. * * @private */ _parser: _PdfContentParserHelper; /** * Cross-reference of the loaded document. * * @private */ _crossReference: _PdfCrossReference; /** * Internal low-level processor to update page contents / annotations. * * @private */ _object: _PdfRedactionProcessor; /** * Initializes a new instance of the `PdfRedactor` class. * * @param {PdfDocument} document The PDF document to which the redactions will be applied. * @throws {Error} If the document is null, undefined, or not a loaded document instance. * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Initialize a new instance of the `PdfRedactor` class * let redactor: PdfRedactor = new PdfRedactor(document); * // Initialize a new instance of the `PdfRedactionRegion` class. * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x: 40, y: 41.809, width: 80, height: 90}); * // Sets the fill color used to fill the redacted area. * redaction.fillColor = {r: 255, g: 0, b: 0}; * redactions.push(redaction); * // Add redactions with specified options. * redactor.add(redactions); * // Apply redactions on the PDF document * redactor.redactSync(); * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` */ constructor(document: PdfDocument); /** * Initializes a new instance of the `PdfRedactor` class with the specified redactions. * * @param {PdfDocument} document The PDF document to which the redactions will be applied. * @param {PdfRedactionRegion[]} redactions An array of redaction objects. * @throws {Error} If the document is null, undefined, or not a loaded document instance. * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Add redactions to the collection * let redactions: PdfRedactionRegion[] = []; * // Initialize a new instance of the `PdfRedactionRegion` class. * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x: 40, y: 41.809, width: 80, height: 90}); * // Sets the fill color used to fill the redacted area. * redaction.fillColor = {r: 255, g: 0, b: 0}; * redactions.push(redaction); * // Initialize a new instance of the `PdfRedactor` class with redactions * let redactor: PdfRedactor = new PdfRedactor(document, redactions); * // Apply redactions on the PDF document * redactor.redactSync(); * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` */ constructor(document: PdfDocument, redactions: PdfRedactionRegion[]); /** * Add redactions with specified options. * * @param {PdfRedactionRegion[]} redactions An array of redaction objects to specify the page index, bounds and appearance of the redaction to be applied. * @returns {void} Nothing. * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Add redactions to the collection * let redactions: PdfRedactionRegion[] = []; * // Initialize a new instance of the `PdfRedactor` class * let redactor: PdfRedactor = new PdfRedactor(document); * // Initialize a new instance of the `PdfRedactionRegion` class. * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x: 40, y: 41.809, width: 80, height: 90}); * // Sets the fill color used to fill the redacted area. * redaction.fillColor = {r: 255, g: 0, b: 0}; * redactions.push(redaction); * // Add redactions with specified options. * redactor.add(redactions); * // Apply redactions on the PDF document * redactor.redactSync(); * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` */ add(redactions: PdfRedactionRegion[]): void; /** * Redacts all marked regions in the PDF document synchronously. * * This method removes text and vector content within the specified redaction regions. It does **not** support image redaction.To redact images inside the PDF, use the asynchronous `redact()` method instead. * * @returns {void} Nothing. * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Add redactions to the collection * let redactions: PdfRedactionRegion[] = []; * // Initialize a new instance of the `PdfRedactor` class * let redactor: PdfRedactor = new PdfRedactor(document); * // Initialize a new instance of the `PdfRedactionRegion` class. * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x: 40, y: 41.809, width: 80, height: 90}); * // Sets the fill color used to fill the redacted area. * redaction.fillColor = {r: 255, g: 0, b: 0}; * redactions.push(redaction); * // Add redactions with specified options. * redactor.add(redactions); * // Apply redactions on the PDF document * redactor.redactSync(); * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` */ redactSync(): void; /** * Redacts all marked regions in the PDF document. * * @param {Function} callBack - A function that supplies a canvas element along with the current application platform.The canvas is used internally to render and redact image content. * @returns {void} A promise that resolves once all redactions have been applied. * * ```typescript * // Load an existing PDF document * let doc: PdfDocument = new PdfDocument(data, password); * // Add redactions to the collection * let redactions: PdfRedactionRegion[] = []; * // Initialize a new instance of the `PdfRedactor` class * let redactor: PdfRedactor = new PdfRedactor(doc); * // Initialize a new instance of the `PdfRedactionRegion` class. * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x: 40, y: 41.809, width: 80, height: 90}); * // Sets the fill color used to fill the redacted area. * redaction.fillColor = {r: 255, g: 0, b: 0}; * redactions.push(redaction); * // Add redactions with specified options. * redactor.add(redactions); * // 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 }; * }; * // Apply redactions on the PDF document * await redactor.redact(callBack: canvasRenderCallback); * // Save the document * doc.save('output.pdf'); * // Destroy the document * doc.destroy(); * ``` */ redact(callBack: canvasRenderCallback): Promise; /** * Converts any found redaction annotations into internal redaction regions, * creating their appearance streams and removing the original annotations. * * @private * @param {PdfPage} page The page whose annotations are analyzed. * @returns {void} nothing. */ _applyRedaction(page: PdfPage): void; /** * Computes page-space bounds for a rectangle after accounting for page rotation. * * @private * @param {PdfPage} page The page containing the bounds. * @param {Rectangle} bounds Unrotated rectangle. * @returns {Rectangle} Rotated-normalized rectangle. */ _calculateRotatedBounds(page: PdfPage, bounds: Rectangle): Rectangle; /** * Appends the given list of redaction regions into the class-wide accumulator. * * @private * @param {PdfRedactionRegion[]} options Redaction regions for a page. * @returns {void} nothing. */ _combineBounds(options: PdfRedactionRegion[]): void; /** * Writes a record back to a content stream, optionally replacing text showing operands. * * @private * @param {_PdfRecord[]} recordCollection The record collection for the page content. * @param {number} index Current record index. * @param {string} updatedText Updated text. * @param {_PdfContentStream} stream The destination stream to write to. * @returns {void} nothing. */ _optimizeContent(recordCollection: _PdfRecord[], index: number, updatedText: string, stream: _PdfContentStream): void; /** * Encodes a JavaScript string into a byte array (UTF-16 code units cast down). * * @private * @param {string} text Input text. * @returns {number[]} Byte array of char codes. */ _getBytes(text: string): number[]; /** * Returns whether the given rectangle intersects or lies within any of the provided redaction regions. * * @private * @param {Rectangle} values Candidate rectangle. * @param {PdfRedactionRegion[]} redactionBounds Redaction regions list. * @returns {boolean} `true` if found; otherwise, `false`. */ _isFoundBounds(values: Rectangle, redactionBounds: PdfRedactionRegion[]): boolean; /** * Checks if a point lies within an axis-aligned rectangle (inclusive edges). * * @private * @param {{x: number, y: number, width: number, height: number}} bounds Rectangle bounds. * @param {number[]} point Point as `[x, y]`. * @returns {boolean} `true` if the point is inside; otherwise, `false`. */ _contains(bounds: { x: number; y: number; width: number; height: number; }, point: number[]): boolean; /** * Tests two rectangles for intersection. * * @private * @param {{x: number, y: number, width: number, height: number}} rect1 First rectangle. * @param {{x: number, y: number, width: number, height: number}} rect2 Second rectangle. * @returns {boolean} `true` if they intersect; otherwise, `false`. */ _intersectsWith(rect1: { x: number; y: number; width: number; height: number; }, rect2: { x: number; y: number; width: number; height: number; }): boolean; /** * Splits a hex string literal into chunks, accounting for line-break artifacts. * * @private * @param {string} hexString Hex string literal. * @returns {string[]} Array of hex chunks without wrapper. */ _splitHexString(hexString: string): string[]; /** * Builds replacement text for glyphs intersecting redaction regions and returns a new TJ array text. * * @private * @param {TextGlyph[]} glyph Glyphs extracted from the operator. * @param {string[]} text Decoded text units. * @param {string} originalText Original operand text. * @param {string[]} decodeText Decoded segments mapped from original text. * @returns {string} Updated TJ array text or original if nothing replaced. */ _replacedText(glyph: TextGlyph[], text: string[], originalText: string, decodeText: string[]): string; /** * Maps decoded text segments to glyph slices while preserving substring boundaries. * * @private * @param {string[]} mainTextCollection Text segments. * @param {TextGlyph[]} imageGlyph Full glyph list aligned with extracted text. * @returns {_TextGlyphMapper[]} Mapped text-glyph segments. */ _mapString(mainTextCollection: string[], imageGlyph: TextGlyph[]): _TextGlyphMapper[]; }