valerybokov opened a new pull request, #571:
URL: https://github.com/apache/pdfbox/pull/571

   ### 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 is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to