Skip to content

Include the /ActualText of marked content in getTextContent - #22473

Closed
0x70b1a5 wants to merge 1 commit into
mozilla:masterfrom
0x70b1a5:text-content-actual-text
Closed

0x70b1a5 wants to merge 1 commit into
mozilla:masterfrom
0x70b1a5:text-content-actual-text

Conversation

@0x70b1a5

@0x70b1a5 0x70b1a5 commented Nov 8, 2026

Copy link
Copy Markdown

A PDF can draw glyphs whose decoded text is wrong and give the correct text in an /ActualText span.
A common example is a small-caps font that stores each glyph in the wrong case.
pdftotext and other extractors use the span text in place of the glyphs.
getTextContent drops it, so callers cannot do the same.

This change adds an actualText property to beginMarkedContentProps items.
It is set only when the property list is an inline dictionary with a string /ActualText.
The value is decoded with stringToPDFString.
Other items do not change, and the text layer does not use the new property.

A caller can now replace the items between the begin and end markers with the span text.
This is the same as the replacement text rule in section 14.9.4 of the specification.

Tests: a new unit test in evaluator_spec.js covers a PDFDocEncoding string, a UTF-16BE string, a non-string value and no value.
The test fails without the change.
The evaluator, struct tree, text layer and text content API specs pass, and gulp lint passes.

A PDF can draw glyphs whose decoded text is wrong and give the correct
text in an /ActualText span. getTextContent drops this text, so a caller
cannot replace the glyphs with it, as pdftotext does.

Add an `actualText` property to `beginMarkedContentProps` items when the
property list is an inline dictionary with a string /ActualText.
@0x70b1a5

0x70b1a5 commented Nov 8, 2026

Copy link
Copy Markdown
Author

This duplicates #22315, which was opened first. I close this PR in favour of it.

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