Commit Graph

324 Commits

Author SHA1 Message Date
Samkit Jain b132d45db5 Fix bug in dedup_chars() in which ._objects was accessed before assignment
Fixes #293
2020-10-20 17:02:07 +05:30
Jeremy Singer-Vine 04fd56ac40 Add utils/page.dedupe_chars(...) (#71 + #280)
h/t @xv44586 for the initial inspiration 👍

These new methods return a version of the chars/page with duplicate
chars — those sharing the same text, fontname, size, and positioning
(within `tolerance` x/y) as other characters — removed.
2020-10-03 12:06:48 -04:00
Jeremy Singer-Vine eeacbe9faa Merge branch 'stable' into develop 2020-10-03 11:54:08 -04:00
Jeremy Singer-Vine 3afd08620f Merge pull request #282 from jsvine/update-trigger-action
Update GitHub Actions to run on pull request events
2020-10-03 11:51:21 -04:00
Samkit Jain ee69b69871 Update GitHub Actions to run on pull request events
In #279 `pull_request_target` was added which is now replaced with just `pull_request`
2020-10-01 21:33:40 +05:30
Jeremy Singer-Vine e810a4a3d3 Merge branch 'stable' into develop 2020-09-29 23:59:13 -04:00
Jeremy Singer-Vine c95f4fd058 Merge pull request #279 from jsvine/fix/fork-repo-workflow-run
Allow GitHub Actions workflow to run on pull requests from forked repos
2020-09-29 23:58:51 -04:00
Jeremy Singer-Vine ec9a0bf108 Merge branch 'stable' into fix/fork-repo-workflow-run 2020-09-29 23:53:22 -04:00
Jeremy Singer-Vine 6b8a590373 Pin psf/black and flake8 dependencies 2020-09-29 23:51:24 -04:00
Samkit Jain 81253b6181 Allow GitHub Actions workflow to run on pull requests from forked repos 2020-09-29 13:17:38 +05:30
Jeremy Singer-Vine 3c5041a20b [docs] Fix broken link README's CLI example #264
Thanks to @flaprocha for spotting this.
2020-09-01 09:02:05 -04:00
Jeremy Singer-Vine be32e570ae [docs] Fix broken link README's CLI example #264
Thanks to @flaprocha for spotting this.
2020-09-01 08:57:27 -04:00
Jeremy Singer-Vine 3031355b50 Merge pull request #260 from jsvine/fix/complexity
- Refactor several complex methods
- Add `extra_attrs` to `.extract_words(...)`
- Add `use_text_flow` to `.extract_words(...)`
2020-08-31 22:05:51 -04:00
Samkit Jain cb924346bb [changelog] Fix commit hash hyperlinks
Added hyperlinks for issues and pull request references as well
2020-08-31 14:44:54 +05:30
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 08cf2ec8e1 Link extra_attrs documentation to list of props
h/t @samkit-jain for the suggestion
2020-08-30 13:29:51 -04:00
Jeremy Singer-Vine 5d51940bbb [changelog] Hyperlink & standardize commit hashes
h/t @samkit-jain for the suggestion
2020-08-30 13:29:33 -04:00
Jeremy Singer-Vine b050870824 Reformat page.py (per newer version of psf/black) 2020-08-29 16:27:14 -04:00
Jeremy Singer-Vine 0eaaf91ebd Update CHANGELOG.md 2020-08-29 16:21:28 -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 6233bbd6ed Speed up test_ca_warn_report:test_objects
The same goals can be acheived by just testing the first page, instead
of the entire PDF, trimming approximately 20% off the total test suite's
execution time, although YMMV.
2020-08-29 13:35:47 -04:00
Jeremy Singer-Vine 917467a10c Remove test_issues.py:test_pr_77 to speed up tests
The test, responding to PR #77, was particularly slow and the
accompanying PDF somewhat large. Now that the fixes to the issues
identified in the PR are fairly tightly integrated into pdfplumber, we
can remove the tests with reasonable confidence, speeding up development
time.
2020-08-29 13:31:42 -04:00
Jeremy Singer-Vine 1f87898857 Refactor/simplify Page.process_objects
This commit reworks the Page.process_objects method to be less complex
and more readable. Many of the changes stem from a realization that
pdfminer.six already stores most object attributes in the desired type;
we only need to convert those requiring decimalization.

This results in one notable change to the output, which is that
`upright` is no longer converted from a bool to an int. The necessary
downstream changes are reflected in utils.extract_words and convert.py.

Overall the changes result in no substantial change to performance; it
is possible that the code runs ever-so-slightly faster, but to a barely
detectable degree.
2020-08-29 13:25:34 -04:00
Jeremy Singer-Vine 8e74cb9553 Remove reference/access to .figures
Per diagram and explanation in [1], LTFigure is just a layout-estimated
collation of LTCurve objects. For consistency with the rest of
pdfplumber, removing it from the list of parsed/accessible objects,
although we still do process the curves within each figure.

[1] https://github.com/pdfminer/pdfminer.six/blob/develop/docs/source/topic/converting_pdf_to_text.rst
2020-08-26 08:49:30 -04:00
Jeremy Singer-Vine a74d3bc7e1 Reduce McCabe complexity of convert.serialize(...) 2020-08-25 22:40:44 -04:00
Jeremy Singer-Vine 59a7dd2100 [docs] Note PyMuPDF's lack of easy shape-access 2020-08-25 22:18:40 -04:00
Jeremy Singer-Vine 9b40f35f0a [docs] Fix typo 2020-08-21 09:46:08 -04:00
Jeremy Singer-Vine d2f5896dac Merge pull request #258 from jsvine/develop
Add comparisons to other Python PDF libraries
2020-08-21 09:42:34 -04:00
Jeremy Singer-Vine 23bebf4c16 Merge branch 'develop' into stable 2020-08-21 09:38:04 -04:00
Jeremy Singer-Vine e2539786b5 [docs] Add comparison to other libraries (#257)
Thanks to @MartinThoma for the idea.
2020-08-21 09:32:41 -04:00
Jeremy Singer-Vine c2f92a9a8e [docs] Tweak note re. former Python 3.5 support 2020-08-21 09:32:07 -04:00
Jeremy Singer-Vine a7df740d1f Merge pull request #256 from jsvine/develop
Merge v0.5.23 into stable branch
2020-08-15 13:03:21 -04:00
Jeremy Singer-Vine d2e7cfdc1b Bump to v0.5.23 🎉 v0.5.23 2020-08-15 12:55:30 -04:00
Jeremy Singer-Vine fb45890bc5 Update changelog 2020-08-15 12:55:12 -04:00
Jeremy Singer-Vine 4f60d9e3bb Remove .travis.yml & link README to Actions tests 2020-08-15 12:13:37 -04:00
Samkit Jain 3b1e23a23a Use f-strings for string formatting 2020-08-15 12:03:34 -04:00
Samkit Jain baf103307b Drop support for Python 3.5 2020-08-15 12:03:34 -04:00
Samkit Jain 1aa921b39c Split the main GA job into 2 separate linting and testing jobs 2020-08-15 12:03:34 -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
Samkit Jain 90f767ff24 Update GitHub Actions workflow 2020-08-15 12:03:34 -04:00
Jeremy Singer-Vine 798a152156 [README] Remove email address, add maintainer list 2020-08-15 09:18:40 -04:00
Jeremy Singer-Vine d8a2f93098 Fix: Raise ValueError on crop w/ zero-overlap bbox
h/t @samkit-jain for catching, per example in #245
2020-08-15 09:18:00 -04:00
Jeremy Singer-Vine 3786b1adec Reformat recent code per psf/black 2020-08-13 22:31:53 -04:00
Jeremy Singer-Vine ddafd627f4 Update changelog 2020-08-13 22:29:30 -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 6c9f8db9b6 Fix CLI test & GitHub action 2020-08-13 21:35:06 -04:00
Jeremy Singer-Vine 76583d9f33 Add make lint 2020-08-13 08:58:13 -04:00
Jeremy Singer-Vine 6d88c5dc6e Fix flake8 violations & .serialize's decode logic 2020-08-13 08:57:06 -04:00
Jeremy Singer-Vine fb0c607985 Update changelog 2020-08-13 08:42:40 -04:00