Commit Graph

10 Commits

Author SHA1 Message Date
Jeremy Singer-Vine b4b0282730 Make tests flake8-compatible 2020-12-16 22:29:51 -05:00
Jeremy Singer-Vine 5c62be2e16 Format all tests with psf/black 2020-12-16 22:19:17 -05:00
Jeremy Singer-Vine d6309a9b47 Add "direction" attribute to extracted words
"direction" == 1 when upright words go LTR and non-upright words go TTB,
and -1 when the opposite is true. This attribute should help in reusing
the results of `.extract_words` in other functions, so that the user
knows how the extracted word corresponds to the word's layout on the
page.
2020-08-30 22:30:14 -04:00
Jeremy Singer-Vine 84f91811df Rework .extract_words and add use_text_flow param
Taking @samkit-jain's smart question about sort-order into account, this
commit reworks `.extract_words`, making the sorting more explicit, and
adding an option to *not* sort, via `use_text_flow=True`, which follows
the original PDF's text flow, rather than presorting all characters top-down,
left-right.

To do so required rethinking the word-delineation logic,
which in turn motivated a shift toward a more object-oriented approach
(especially to keep track of settings without passing them from function
to function). Now `.extract_text`'s logic is encapsulated in a new class,
`TextExtractor`.
2020-08-30 18:36:03 -04:00
Jeremy Singer-Vine c8b200ee7c Refactor .extract_words and allow attrib-grouping
This commit refactors and hopefully makes clearer the logic in
utils.extract_words. It also adds a new parameter, `extra_attrs`, which
allows the user to pass a list of attributes on which to group all
characters.

For instance, passing `extra_attrs=["fontname", "size"]` will not allow
characters with different font names or sizes to become part of the same
word. As a benefit, those resulting word dicts will contain `"fontname"`
and `"size"` attributes — providing a long-requested feature (cf. issue
2020-08-29 16:05:31 -04:00
Jeremy Singer-Vine a5e7d7fa52 Remove pandas from dev requirements and tests
Results in needing one more # pragma: nocover statement, but on a
simple line of code. See PR #253 for details and motivation.
2020-08-15 12:03:34 -04:00
Jeremy Singer-Vine 047ad345b4 Add relative param to .crop & err on invalid boxes
Addresses https://github.com/jsvine/pdfplumber/issues/245

Also adds `relative` param to .within_bbox, and adds a new
utils.calculate_area(bbox) method.
2020-08-13 22:25:58 -04:00
Jeremy Singer-Vine cbc91c67d0 Add convert.py/.to_json/.to_csv & improve testcov
Moves most of the logic previously in cli.py to convert.py, for usage by
other submodules. Adds Container.to_json and Container.to_csv. Makes
adjustments/fixes to other parts of the library, based on edge-cases
encountered (such as infinite recursion in anntations).
2020-08-13 08:37:46 -04:00
Jeremy Singer-Vine 8320d6479d Change .move_to_avg to .snap_objects & mv to utils
Also: Simplify the function, and make it based on the attribute you want
to snap *to*, not just the axis/orientation across which to snap.
2020-08-05 22:52:36 -04:00
Jeremy Singer-Vine d16aa13ca2 Fix utils.extract_words & .resize_object, + tests
- Fixes `.extract_words`, which had been returning incorrect results when `horizontal_ltr = False`
- Fixes `.resize_object`, which had been failing in various permutations
- Brings utils.py test coverage to 100%
2020-08-01 12:27:07 -04:00