ReplaceTextBlockCharSourceBytes

Text, Extraction, Content streams, Document editing

Description

Replaces the encoded source-byte range mapped to one extracted character in the selected document

Syntax

Delphi

Function TPDFlib.ReplaceTextBlockCharSourceBytes(TextBlockListID, Index,
  CharIndex: Integer; Const NewSource: AnsiString): Integer;

Parameters

TextBlockListIDHandle returned by ExtractPageTextBlocks for the selected document
Index1-based text block index
CharIndex1-based UTF-16 code-unit position inside the block text
NewSourceRaw replacement bytes in the active PDF font encoding, not Unicode text

Return values

1The mapped byte range was replaced and its page content layer was rewritten
0The location is invalid, stale or read-only, or the content layer could not be rewritten

Error codes

PDFLIB_ERROR_TEXT_LOCATION_INVALIDThe list, index, location or content instruction is invalid
PDFLIB_ERROR_TEXT_LOCATION_STALEThe target page content layer has changed since extraction
PDFLIB_ERROR_TEXT_LOCATION_READ_ONLYThe character is generated, substituted by /ActualText, nested in a Form, transcoded before font mapping, or split across content layers

Remarks

The method rewrites only the containing page content layer and preserves adjacent Tj strings, TJ array strings and kerning numbers

Two independent fingerprints detect stale content before parsing and writing, so an old extraction result cannot silently target changed bytes

Re-extract page text after every successful replacement because all locations from the previous list are stale

Ligature-expanded characters share one source range and should be treated as one source glyph

The selected page is restored after success or failure