Skip to content

PDFBOX-6338 Fix actual text state between pages - #571

Closed
valerybokov wants to merge 2 commits into
apache:trunkfrom
valerybokov:fix-ActualText-state-between-pages
Closed

valerybokov wants to merge 2 commits into
apache:trunkfrom
valerybokov:fix-ActualText-state-between-pages

Conversation

@valerybokov

Copy link
Copy Markdown

Problem

If a page has an /ActualText marked-content sequence that isn't closed (a BDC without its EMC),
PDFTextStripper keeps applying it to all following pages:

page 1:  /Span <</ActualText (X)>> BDC  (one) Tj        % no EMC
page 2:  (two) Tj

Expected X and two, but the text of page 2 is lost: every glyph after the first one in an ActualText
sequence is replaced with an empty string. The state also survives into the next document if the same
stripper is reused, so a valid document can come out empty.

Cause

currentMarkedContents, actualText, actualTextMarkedContent and firstActualTextPosition are only
changed by the BDC/BMC/EMC operators, and nothing resets them between pages or in resetEngine().

Fix

processPage() clears these fields before the page's content is processed. A marked-content sequence
can't span pages, so nothing valid is lost. Every page goes through processPage(), so this also covers
the first page of the next document.

Test

TestTextStripper#testUnclosedActualText extracts a two-page document whose first page leaves
ActualText(X) open (expects X\ntwo\n), then a second document with the same stripper (expects
three\n). It fails without the fix. TestTextStripper, BidiTest and PDFTextStripperByAreaTest pass.


Per https://www.apache.org/legal/generative-tooling.html: portions of this PR were
produced with assistance from Claude Code (Anthropic).

I've reviewed the generated code and confirm to the best of my knowledge that the output does not include any
third-party copyrighted material and is compatible with the Apache License 2.0.

valerybokov and others added 2 commits November 20, 2026 15:15
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…losed on a page

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@THausherr

Copy link
Copy Markdown
Contributor

Please create a JIRA ticket, this looks like a bug.

@valerybokov valerybokov changed the title Fix actual text state between pages PDFBOX-6338 Fix actual text state between pages Nov 20, 2026
asf-gitbox-commits pushed a commit that referenced this pull request Nov 21, 2026
asf-gitbox-commits pushed a commit that referenced this pull request Nov 21, 2026
@valerybokov
valerybokov deleted the fix-ActualText-state-between-pages branch November 21, 2026 17:23
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.

2 participants