Qu

pdf.replace_text

Builtin index · File I/O

pdf.replace_text(src, old, new, [page=], [count=], [case_sensitive=true])

Input: src, old, new, page, count, case_sensitive · Output: no output

What it is

Changes text in an existing PDF and returns the edited file as a Vec of bytes (save with bytes_write). Edits the strings of Tj/TJ/'/" operators (literal or hex, Flate decoded) in page content streams, for simple fonts (Type1/TrueType, one byte per glyph): a match may span several strings of one TJ array or several consecutive show operators, and a TJ gap wider than a space matches a space. page= limits the edit to one page, count= to the first N replacements, case_sensitive=false folds case. Pages it does not change are left byte-identical. Refuses with a named error (never a corrupted file) when nothing can be replaced: text in a composite Type0/CID font (the error names the font), text only in a Form XObject, text split by positioning/colour operators, or a replacement character the font cannot show; in a subset font (ABCDEF+Name) or a Type3 font (matplotlib's default) only characters already shown on that page can be used. Nothing is reflowed: a longer replacement keeps its starting point and can overlap what follows.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
pdf.replace_text(src, old, new, [page=], [count=], [case_sensitive=true])
src —not documented yet
old —not documented yet
new —not documented yet
page optionalpage= limits the edit to one page, count= to the first N replacements, case_sensitive=false folds case.
count optionalpage= limits the edit to one page, count= to the first N replacements, case_sensitive=false folds case.
case_sensitive optional (default true)page= limits the edit to one page, count= to the first N replacements, case_sensitive=false folds case.
not documented yetChanges text in an existing PDF and returns the edited file as a Vec of bytes (save with bytes_write). Pages it does not change are left byte-identical. Nothing is reflowed: a longer replacement keeps its starting point and can overlap what follows.

Examples

No documentation example calls this form yet. The File I/O chapter is where one belongs.