[ 
https://issues.apache.org/jira/browse/PDFBOX-6346?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tilman Hausherr updated PDFBOX-6346:
------------------------------------
    Affects Version/s: 2.0.37

> The article list never shrinks
> ------------------------------
>
>                 Key: PDFBOX-6346
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6346
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Text extraction
>    Affects Versions: 2.0.37, 3.0.8 PDFBox, 4.0.0
>            Reporter: Valery Bokov
>            Priority: Major
>              Labels: pull-request-available, test
>
> *Problem*
> _charactersByArticle_ has one list per article of a page (before, in and 
> after each bead), but it
> never shrinks. A page with fewer beads than an earlier page keeps the extra 
> lists, and _writePage()_ writes an empty article for each of them. With 
> `[`/`]` as article start/end, a page without beads that follows a page with 
> two beads gives
> [][][][][three]
> instead of {_}[three]{_}. With {_}setAddMoreFormatting(true){_}, where 
> article start and end are line
> separators, this shows up as extra empty lines.
> *Cause*
> In {_}processPage(){_}, the _remove( i )_ branch can't be reached: it's in 
> the _else_ of {_}i < originalSize{_}, and since {_}i < 
> Math.max(numberOfArticleSections, originalSize){_}, i >= originalSize means 
> {_}numberOfArticleSections > originalSize{_}, so _numberOfArticleSections < 
> originalSize_ is always false. The TODO next to it ("Looks like decrement 
> (--i) needed ... never reached in tests?!") noticed this, but a decrement 
> wouldn't help.
> *Fix*
> The loop is replaced: lists beyond the number needed are removed with 
> {_}subList(...).clear(){_}, the remaining lists are cleared, and missing 
> lists are added. The list now has exactly one entry per article of the 
> current page, so text outside all beads also goes into the real "after the 
> last bead" list ({_}charactersByArticle.size() - 1{_}) instead of a leftover 
> one.
> _PDFTextStripperByArea_ sets its own list for each region and page, and 
> _PDFText2HTML_ only reads it, so neither is affected.
> *Test*
> _TestTextStripper#testFewerBeadsThanPreviousPage_ extracts a page with two 
> beads followed by a page without beads and expects 
> {_}[][one][][two][]\n[three]\n{_}. It fails without the fix. 
> {_}TestTextStripper{_}, _BidiTest_ and _PDFTextStripperByAreaTest_ pass.



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