Valery Bokov created PDFBOX-6346:
------------------------------------
Summary: 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: 3.0.8 PDFBox, 4.0.0
Reporter: Valery Bokov
*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]