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
| TextBlockListID | Handle returned by ExtractPageTextBlocks for the selected document |
|---|---|
| Index | 1-based text block index |
| CharIndex | 1-based UTF-16 code-unit position inside the block text |
| NewSource | Raw replacement bytes in the active PDF font encoding, not Unicode text |
Return values
| 1 | The mapped byte range was replaced and its page content layer was rewritten |
|---|---|
| 0 | The location is invalid, stale or read-only, or the content layer could not be rewritten |
Error codes
PDFLIB_ERROR_TEXT_LOCATION_INVALID | The list, index, location or content instruction is invalid |
|---|---|
PDFLIB_ERROR_TEXT_LOCATION_STALE | The target page content layer has changed since extraction |
PDFLIB_ERROR_TEXT_LOCATION_READ_ONLY | The 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