Commit Graph

29 Commits

Author SHA1 Message Date
Jeremy Singer-Vine 03a477f7f0 Add pdfplumber.open(unicode_norm=...)
Allows user to pre-normalize Unicode characters.

h/t @petermr + @agusluques in #905
2024-08-04 14:11:58 -04:00
Jeremy Singer-Vine 22494e8da2 Make Page.crop(...) also crop .annots/.hyperlinks
h/t @Safrone in #1171
2024-08-04 13:14:12 -04:00
Jeremy Singer-Vine e5737d29c2 Fix broken CroppedPage.annots/hyperlinks
Issue was caused by missing `.initial_doctop` and `.rotation`
properties. h/t @Safrone in #1171
2024-07-14 17:27:05 -04:00
Jeremy Singer-Vine aaa35c9c6b Fix coordinates of annots on rotated pages
PDFs represent annotation coordinates independently from page rotation,
so annot coordinates have to be adjusted.
2024-06-11 14:52:03 -04:00
Jeremy Singer-Vine 07d9997ee5 Standardize handling of cropbox
... fixing various issues with PageImage. Also adds
force_mediabox parameter to Page.to_image(...).

Thanks to @stefanw for flagging:
    https://github.com/jsvine/pdfplumber/issues/1054
2024-01-05 10:14:44 -05:00
Jeremy Singer-Vine 57d51bb5f4 Normalize color representation (#917)
This commit normalizes the type representation of `stroking_color` and
`non_stroking_color` values. Thanks to @dhdaines for pointing out this
inconsistency.

Previously, `pdfplumber` passed along `pdfminer.six`'s colors without
normalization. Due to quirks in `pdfminer.six`'s color handling, this
meant that those values could be floats, ints, lists, or tuples. This
commit normalizes all color values (when non-None) into n-tuples, where
(val,) represents grayscale colors, (val, val, val) represents RBG, and
(val, val, val, val) represents CMYK colors.

This should solve the consistency issue, although might cause breaking
changes to code that filters for non-tuple values — e.g., `[c for c in
page.chars if c == [1, 0 0]]`. Although breaking changes are unpleasant,
I think the tradeoff for longer-term consistency is worth it.
2023-07-03 22:59:05 -04:00
Jeremy Singer-Vine 0de6da97fd Fix bug for re-crops that use relative=True (#914)
When using relative=True for a re-crop, pdfplumber was passing the wrong
bounding box to the cropping function. This commit fixes that bug and
also refactors CroppedPage.__init__(...) for clarity and consistency's
sake.
2023-07-02 11:49:53 -04:00
Jeremy Singer-Vine 6f6b465260 Add .curve_edges, use by default in table-detect.
Most of the groundwork was already there to add a PDF/Page.curve_edges
property. And, inspired, by
https://github.com/jsvine/pdfplumber/discussions/858 and related issues,
we now include 0/90/180/270-degree oriented curve segments into the
default table-detection strategy. As before, you can still switch to the
"lines_strict" to use only lines defined as such (rather than also using
rect and curve edges).
2023-04-13 08:13:16 -04:00
Jeremy Singer-Vine 3ab1cc4377 Add utils/Page.outside_bbox(...)
See https://github.com/jsvine/pdfplumber/issues/369
2022-07-20 17:10:35 -04:00
Jeremy Singer-Vine 71ad60f891 Add strict=True/False to .crop/within_bbox(...)
See https://github.com/jsvine/pdfplumber/issues/421
2022-07-20 15:16:03 -04:00
Jeremy Singer-Vine 826e927b7f Remove redundant loading in test_basics.py 2022-05-13 16:42:23 -04:00
Jeremy Singer-Vine b21ae179fe Add tests for PR 581
We cannot test whether the file closed successfully, but we can test
that the code reaches that branch of the logic.
2022-01-13 23:21:43 -05:00
Jeremy Singer-Vine 54cbbc5321 Remove deprecated .load method 2021-12-16 22:22:54 -05:00
Jeremy Singer-Vine d72b879665 Enforce import order via isort 2021-12-16 22:22:54 -05:00
Jeremy Singer-Vine 87b947f8f6 Remove decimalizing (but let CLI adjust precision)
Per discussion at https://github.com/jsvine/pdfplumber/discussions/346
and input from @ramcdona, this commit changes pdfplumber's behavior
regarding floating point numbers. Specifically, it removes all
conversion of floats to Decimal objects. This brings several advantages:

- Increased precision (where applicable)
- Decreased code complexity
- Increased performance (~10% speedup on test suite)
- Increased fidelity to `pdfminer.six` output

These seem to outweigh the disadvantages:

- Some tests break (but have been easily fixed) due to increased
  precision and/or floating point arithmetic artifacts
- Some users' scripts may also break, if they depend on strict equality
  testing, though these *should* also be easily fixable

Because some form of automatic rounding may still be desirable for the
pdfplumber CLI utility, the conversion methods (.to_csv, .to_json) have
been adjusted to accept a `precision` argument.
2021-10-19 21:51:33 -04:00
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 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
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 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 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 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