[
https://issues.apache.org/jira/browse/PDFBOX-4138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16385131#comment-16385131
]
Julien Férard commented on PDFBOX-4138:
---------------------------------------
Ok [~tilman], thanks. If I were involved in this project, I would use a
Strategy pattern to handle this.
Steps:
1. Create an interface:
{code:java}
interface TextPositionDispatcher {
add(TextPosition textPos);
Iterable<List<TextPosition>> getChunks();
}{code}
{{2. Create two classes:}}
{code:java}
class OneArticleTextPositionDispatcher implements TextPositionDispatcher {
// a wrapper around a simple List<TextPosition>
// add(TextPosition textPos) adds the text pos to the list
// getChunks() returns Collections.singletonList(list);
}
class BeadsTextPositionDispatcher implements TextPositionDispatcher {
// a wrapper around charactersByArticle
// add(TextPosition textPos) selects the index as in current implementation
and puts the textPos in the corresponding list
// getChunks() returns charactersByArticle.
}{code}
3. Create a field {{textPositionDispatcher}} in {{PDFTextStripper.}}
At first, {{textPositionDispatcher = new OneArticleTextPositionDispatcher();}}
When one selects {{setShouldSeparateByBeads(true)}}, then
{{textPositionDispatcher = new BeadsTextPositionDispatcher();}}
Nothing new so far.
4. Add two new methods:
{code:java}
setTextPositionDispatcher(TextPositionDispatcher dispatcher) {
textPositionDispatcher = dispatcher;
}
getTextPositionDispatcher() {
return textPositionDispatcher;
}
{code}
Now, it's possible to use one's own dispatcher, and the issue is isolated. And
it's possible to change the default implementation with little impact on the
rest of the class.
> PDFTextStripper: error in a comparison
> --------------------------------------
>
> Key: PDFBOX-4138
> URL: https://issues.apache.org/jira/browse/PDFBOX-4138
> Project: PDFBox
> Issue Type: Bug
> Components: Text extraction
> Affects Versions: 2.0.8
> Reporter: Julien Férard
> Priority: Minor
>
> This is very simple. Maybe I'm wrong, but in PdfTextStripper, l. 844
>
> [https://github.com/apache/pdfbox/blob/0e07344c0e3a932f0ca346f7cac4700882c67b5d/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java#L844]
> * You want to check if the pos is on the left *and* above the rectangle
> (this is better than just on the left or just above);
> * The name of the variable contains "LeftAndAbove".
> ...and the code contains a `||` (or).
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]