PdfEx.ContentEdit (pdf_ex v0.1.0)

Copy Markdown View Source

Run-level text replacement.

replace_text/3 swaps the entire string of the show op (Tj/TJ) containing a glyph UID. It is a token-span patch over the parsed content-stream operator list — the untouched remainder of the stream is never regenerated — and marks only the /Contents object dirty.

Width compensation (spec D5): Td/TD/Tm/T*/'/" all reset the text matrix from the line matrix, so a follower positioned by any of them does NOT drift when this run's advance changes and is never touched. Only a directly consecutive show op inherits the drift; in that case the width delta is folded into a trailing TJ kern INSIDE the edited op, restoring the post-run text matrix so every downstream byte stays identical.

Single-byte fonts only. Composite (CID/Type0) fonts are rejected.

Summary

Functions

Deletes the single grapheme addressed by uid from its run, via a run-level replace (inherits T2.1 encoding, CID guard, and width compensation).

Decoded text of the run (show op) addressed by uid.

Functions

delete_glyph(doc, uid)

@spec delete_glyph(PdfEx.Document.t(), binary()) ::
  {:ok, PdfEx.Document.t()} | {:error, PdfEx.Error.t()}

Deletes the single grapheme addressed by uid from its run, via a run-level replace (inherits T2.1 encoding, CID guard, and width compensation).

replace_text(doc, uid, new_text)

@spec replace_text(PdfEx.Document.t(), binary(), String.t()) ::
  {:ok, PdfEx.Document.t()} | {:error, PdfEx.Error.t()}

run_text(doc, uid)

@spec run_text(PdfEx.Document.t(), binary()) ::
  {:ok, String.t()} | {:error, PdfEx.Error.t()}

Decoded text of the run (show op) addressed by uid.