Valery Bokov created PDFBOX-6338:
------------------------------------

             Summary: reset ActualText state in PDFTextStripper at the start of 
each page
                 Key: PDFBOX-6338
                 URL: https://issues.apache.org/jira/browse/PDFBOX-6338
             Project: PDFBox
          Issue Type: Bug
    Affects Versions: 3.0.8 PDFBox
            Reporter: Valery Bokov
             Fix For: 3.0.9 PDFBox, 4.0.0


*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.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to