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

   ### Problem
   
   `PDFTextStripper.getText()` throws an `IndexOutOfBoundsException` with 
default settings when a page has
   article beads and a new article starts on the same baseline as the previous 
one, e.g. two beads side by side:
   
       java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
           at java.util.ArrayList.get(ArrayList.java:428)
           at 
org.apache.pdfbox.text.PDFTextStripper.createWord(PDFTextStripper.java:2043)
   
   ### Cause
   
   `lastPosition` in `writePage()` carries over from one article to the next, 
but the `line` buffer is new for
   each article. When the first glyph of the next article overlaps the last 
line of the previous one and is far
   enough to the right, a word separator is added to the still-empty line. 
`normalizeAdd()` then calls
   `createWord("", [])`, and since PDFBOX-6281 (f4dbe77d7b) `createWord()` 
calls `wordPositions.get(0)`
   unconditionally.
   
   ### Fix
   
   `createWord()` checks `isFromActualText()` only when `wordPositions` isn't 
empty. An empty word is
   normalized as before, so the output matches the behavior before PDFBOX-6281: 
`LEFT RIGHT`, not an exception
   (and not `LEFTRIGHT`). The `requireNonNull` check is removed: it could never 
report its message, because
   `get(0)` throws first.
   
   ### Test
   
   `TestTextStripper#testArticlesOnSameLine` builds a page with two thread 
beads side by side, one word in each,
   and expects `"LEFT RIGHT\n"`. It fails with the exception above 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), based on a bug was 
described in Apache PDFBOX Issue Tracker.
   
   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