Skip to content

Replacement text: BeginActualText / EndMarkedContent - #51

Merged
tannevaled merged 1 commit into
mainfrom
feat/actualtext
Oct 22, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/actualtext

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Page.BeginActualText(s) … Page.EndMarkedContent() write a /Span <</ActualText …>> BDC … EMC around what is drawn. Text extraction, copying and search then use the replacement text instead of the glyphs.

The use case is go-slides' code callouts and line numbers in its vector PDF. A disc's digit and the gutter's numbers are drawn as text, and pdftotext interleaves them into the code lines (func main() { 1). With an empty ActualText they are drawn and not extracted.

  • Checked with Poppler's pdftotext 26.10. TestActualTextHiddenFromExtraction runs it when it is installed and skips otherwise; locally, only the text outside the span is extracted.
  • Spans nest. A stray EndMarkedContent writes nothing, and spans left open are closed when the page is written, so the stream stays balanced.
  • The text string uses the existing pdfTextString encoding: ASCII literal, or <FEFF…> UTF-16BE.
  • 100 % coverage locally, gofmt clean. README updated (after v0.16.0).

🤖 Generated with Claude Code

A /Span marked-content sequence with /ActualText gives the text that
extraction, copying and search use instead of the glyphs drawn inside
it. An empty one hides decorations from the text: go-slides draws code
callout discs and line numbers that pdftotext would otherwise interleave
into the code lines. Checked with Poppler's pdftotext 26.10 (a test runs
it when installed): the glyphs inside an empty ActualText are drawn and
not extracted.

Spans nest; a stray End writes nothing; spans left open are closed when
the page is written, so a stream is never unbalanced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 239c264 into main Oct 22, 2026
1 check passed
@tannevaled
tannevaled deleted the feat/actualtext branch October 22, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant