Commit Graph

72 Commits

Author SHA1 Message Date
Jeremy Singer-Vine 7e2dc7cf75 Re-add textboxhorizontal/etc. when laparams (#359)
This commit reinstates access to higher-level layout objects (such as
`textboxhorizontal`) when `laparams` is passed to
`pdfplumber.open(...)`. Had been removed in `0.5.24` via 1f87898.

Also adds a test for this behavior.
2021-02-26 18:53:11 -05:00
Samkit Jain a17c5a72b6 Sort tables extracted on a page by their top position
Fixes #336
h/t @gqh1995 for reporting
2021-01-21 20:05:29 +05:30
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
Samkit Jain 02656b29c8 Update tests to bump up test coverage 2020-12-08 22:48:37 +05:30
Samkit Jain 4ccf8cff67 Resolve lint issues and remove unused imports 2020-11-29 16:29:14 +05:30
Samkit Jain 2d9415cdd0 Recursively parse metadata values to handle nested PDFObjRef objects
Fixes #316
2020-11-29 15:41:01 +05:30
Samkit Jain 9f0a1ad7cd Treat invalid/unparseable metadata values as warnings
Certain invalid values if parseable don't throw a warning and only unparseable (always invalid) throw
2020-11-26 21:58:49 +05:30
Jeremy Singer-Vine 408605f01a Prevent .open(...) from closing ext. file objects
Fixes #312. Now only closes pdfplumber-created streams, not file objects
passed to pdfplumber.open(...).
2020-11-12 23:02:08 -05:00
Samkit Jain 3030765036 Add test for issue #297
h/t @prgx-csmith01 for providing the PDF
2020-10-30 12:47:27 +05:30
Jeremy Singer-Vine f665863daf Fix test_table.py ValueError tests
They were erroring on wrong aspect, because PDF object was being passed
instead of Page object.
2020-10-20 09:42:23 -04:00
Jeremy Singer-Vine bc407790f1 Decimalize "simple" explicit_h/v_lines descs (#290)
... in TableFinder. This way, you can pass ints/floats without
pre-converting them to Decimal objects.
2020-10-20 09:41:49 -04:00
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 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 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 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 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 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 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 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 3f4b4b24b3 Bring pdfplumber/table.py coverage to 100% 2020-08-06 22:19:40 -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
Jeremy Singer-Vine 8e2a166c56 Add coverage for one missing pdf.page method 2020-08-01 10:21:17 -04:00
Jeremy Singer-Vine e7bd308fea Refactor DerivedPage classes & fully test page.py
Previously, classes were being defined dynamically, in a confusing
manner. This new logic should be easier to understand.

This commit also adds a few assertions that bring coverage for page.py
to 100%.
2020-08-01 09:19:27 -04:00
Jeremy Singer-Vine aa03961291 Add .annots and .hyperlinks, replacing .annos
.annos was non-functional, based on a misunderstanding of how
Annotation objects were represented in the PDF object. Also shifts
language from "annos" to "annots" to mirror pdfminer's nomenclature.
2020-07-31 18:02:04 -04:00
Jeremy Singer-Vine c5e5f4b6a9 Add open(path, pages = [...]) test 2020-07-29 23:01:00 -04:00
Jeremy Singer-Vine aede6c259c Add a few more tests 2020-07-26 15:58:06 -04:00
Jeremy Singer-Vine f4aa428334 Add tests for file-loading 2020-07-26 15:46:17 -04:00
Jeremy Singer-Vine 00e789bf42 Shift to making pdfplumber.open the sole loader
- .from_path is now removed
- .load is marked as deprecated, to be removed in 0.6.0
2020-07-26 15:27:51 -04:00
Jeremy Singer-Vine 1ac16dd369 Change testing framework from nosetests to pytest 2020-07-25 08:45:17 -04:00
Jeremy Singer-Vine cddbff74e5 Upgrade pdfminer.six==20200517 and adjust tests
New pdfminer.six version includes some improvements to layout analysis,
and especially char sizes. Tests tweaked accordingly.
2020-07-18 12:50:12 -04:00
Jeremy Singer-Vine 0254da3a47 Merge branch 'idan-david/master' 2020-07-18 11:19:34 -04:00
Idan David 334a49b74c Add test for LTChar colors 2020-05-31 12:14:25 +03:00
Jeremy Singer-Vine d64afa8c2a Fix Page.extract_table(...) when no table found
Return None instead of crashing.

Fixes https://github.com/jsvine/pdfplumber/issues/216
2020-05-27 22:24:23 -04:00
Jeremy Singer-Vine 85f422d001 Fix bug in pdfminer.six's .resolve_all
See https://github.com/jsvine/pdfplumber/issues/203

Root cause of decimalization bug flagged in that issue was
pdfminer.six's .resolve_all method not recusively resolving items within
tuples. Now we define our own method, with some slight optimization
tweaks.
2020-04-29 08:31:39 -04:00
Samkit Jain 0edc6bfadc add missing object type rect_edge to obj_to_edges() 2020-04-07 20:10:18 +05:30
Kwok-kuen Cheung 8d6e52a43c Fix #124 opening PDF with bytes stream 2020-02-05 22:36:19 +08:00
Jeremy Singer-Vine df00787ada Prevent custom LAParams from raising exception
Issue #168 / PR #169. Many thanks to @frascuchon for submitting the PR,
which is the source for the code/idea in this commit.
2020-01-12 23:08:58 -05:00
Jeremy Singer-Vine 6c2e474490 Update pdfminer.six/pillow reqs & bump to v0.5.15 2020-01-05 21:33:49 -05:00
Jeremy Singer-Vine b83afee9fb Add test for PR 138 and thank @samkit-jain 2019-10-06 17:59:39 -04:00
Jeremy Singer-Vine 56a3ac7f2f Fix .extract_table() sorting bug (#140) 2019-10-06 17:41:31 -04:00
Jeremy Singer-Vine 4ef679d6d7 Add test for PR 136 and bump version 2019-08-29 19:05:23 -04:00
Jeremy Singer-Vine 6f70d0937a Add support for parsing password-protected PDFs
Thanks to @nikhilbhawsinka for raising the question in
https://github.com/jsvine/pdfplumber/issues/101

Test PDF via https://www.novapdf.com/pdf-example-files-created-with-novapdf-kb.html
2019-04-14 23:19:16 -04:00
Jeremy Singer-Vine 5843cd7572 Improve PDFObjRef resolution and object conversion
More robust solutions to:

- https://github.com/jsvine/pdfplumber/pull/77
- https://github.com/jsvine/pdfplumber/issues/90
2018-11-11 22:28:46 -05:00