Skip to content

Commit

Permalink
Attempt to fix issues #18 and #15
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLink committed Jan 4, 2018
1 parent c918261 commit 88bfd8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
samples/.DS_Store
10 changes: 7 additions & 3 deletions PDFLayoutTextStripper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Author: Jonathan Link
* Email: jonathanlink[d o t]email[a t]gmail[d o t]com
* Date of creation: 13.11.2014
* Version: 2.2.2
* Version: 2.3
* Description:
*
* Version 2.1 uses PDFBox 2.x. Version 1.0 used PDFBox 1.8.x
Expand Down Expand Up @@ -74,7 +74,7 @@ public PDFLayoutTextStripper() throws IOException {
public void processPage(PDPage page) throws IOException {
PDRectangle pageRectangle = page.getMediaBox();
if (pageRectangle!= null) {
this.setCurrentPageWidth(pageRectangle.getWidth());
this.setCurrentPageWidth(pageRectangle.getWidth() * 1.2); // 1.2 dirty fix (see issue 15)
super.processPage(page);
this.previousTextPosition = null;
this.textLineList = new ArrayList<TextLine>();
Expand Down Expand Up @@ -171,8 +171,11 @@ private int getNumberOfNewLinesFromPreviousTextPosition(final TextPosition textP
float textYPosition = Math.round( textPosition.getY() );
float previousTextYPosition = Math.round( previousTextPosition.getY() );

if ( textYPosition > previousTextYPosition && (textYPosition - previousTextYPosition > 5.5) ) {
if ( textYPosition > previousTextYPosition && (textYPosition - previousTextYPosition > 5.5) ) { // 5.5 dirty fix (see issue 12)
double height = textPosition.getHeight();
if (height == 0) {
height = 1;
}
int numberOfLines = (int) (Math.floor( textYPosition - previousTextYPosition) / height );
numberOfLines = Math.max(1, numberOfLines - 1); // exclude current new line
if (DEBUG) System.out.println(height + " " + numberOfLines);
Expand Down Expand Up @@ -264,6 +267,7 @@ private int computeIndexForCharacter(final Character character) {
}

private boolean isSpaceCharacterAtIndex(int index) {
if (this.line.length() == 0 || index < 0) return false;
return this.line.charAt(index) != SPACE_CHARACTER;
}

Expand Down

0 comments on commit 88bfd8c

Please sign in to comment.