Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text coming in reverse order with boxes flow disabled #399

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Allow boxes_flow LAParam to be passed as None, validate the input, and update documentation ([#395](https://github.com/pdfminer/pdfminer.six/pull/395))

### Fixed
- Text no longer comes in reverse order when advanced layout analysis is disabled ([#398](https://github.com/pdfminer/pdfminer.six/pull/398))
- Updated misleading documentation for `word_margin` and `char_margin` ([#407](https://github.com/pdfminer/pdfminer.six/pull/407))
- Ignore ValueError when converting font encoding differences ([#389](https://github.com/pdfminer/pdfminer.six/pull/389))
- Grouping of text lines outside of parent container bounding box ([#386](https://github.com/pdfminer/pdfminer.six/pull/386))
Expand Down
4 changes: 2 additions & 2 deletions pdfminer/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,9 @@ def analyze(self, laparams):
if laparams.boxes_flow is None:
def getkey(box):
if isinstance(box, LTTextBoxVertical):
return (0, -box.x1, box.y0)
return (0, -box.x1, -box.y0)
else:
return (1, box.y0, box.x0)
return (1, -box.y0, box.x0)
textboxes.sort(key=getkey)
else:
self.groups = self.group_textboxes(laparams, textboxes)
Expand Down
15 changes: 13 additions & 2 deletions tests/test_highlevel_extracttext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

from helpers import absolute_sample_path
from pdfminer.high_level import extract_text
from pdfminer.layout import LAParams


def run_with_string(sample_path):
def run_with_string(sample_path, laparams=None):
if laparams is None:
laparams = {}
absolute_path = absolute_sample_path(sample_path)
s = extract_text(absolute_path)
s = extract_text(absolute_path, laparams=LAParams(**laparams))
return s


Expand All @@ -21,6 +24,9 @@ def run_with_file(sample_path):
"simple1.pdf": "Hello \n\nWorld\n\nHello \n\nWorld\n\n"
"H e l l o \n\nW o r l d\n\n"
"H e l l o \n\nW o r l d\n\n\f",
"simple1.pdf_no_boxes_flow": "Hello \nWorld\nHello \nWorld\n"
"H e l l o \nW o r l d\n"
"H e l l o \nW o r l d\n\f",
"simple2.pdf": "\f",
"simple3.pdf": "Hello\n\nHello\n\nWorld\n\nWorld\n\n\f",
}
Expand All @@ -32,6 +38,11 @@ def test_simple1_with_string(self):
s = run_with_string(test_file)
self.assertEqual(s, test_strings[test_file])

def test_simple1_no_boxes_flow(self):
test_file = "simple1.pdf"
s = run_with_string(test_file, laparams={"boxes_flow": None})
self.assertEqual(s, test_strings["simple1.pdf_no_boxes_flow"])

def test_simple2_with_string(self):
test_file = "simple2.pdf"
s = run_with_string(test_file)
Expand Down