Commit Graph

21 Commits

Author SHA1 Message Date
Jeremy Singer-Vine 30a52cb0ed Add PDF.path & fix .to_image() for zipped files
These are related changes, since the previous approach of using
`PDF.stream.name` to distinguish between on-path and filelike-object PDFs
doesn't work for zipped files (and possibly other filelike-objects that
have a `name` property).
2023-07-29 14:30:00 -04:00
Jeremy Singer-Vine 7e2893106e Add antialias parameter to Page.to_image(...)
... and associated methods. Thanks to @cmdlineluser for flagging.

For details, see:
https://github.com/jsvine/pdfplumber/discussions/899#discussioncomment-6464765
2023-07-19 08:56:18 -04:00
Jeremy Singer-Vine b5c268d756 Fix PNG size tests for other platforms 2023-07-16 17:51:53 -04:00
Jeremy Singer-Vine b0493732c4 Replace Wand with pypdfium2 for page.to_image(...)
This commit swaps out Wand (and its non-Python dependencies ImageMagick
and Ghostscript) for pypdfium2 for PageImage rendering. This has some
advantages:

- Less finicky: Wand often caused users problems, due to "MagickWand
  shared library not found" and "PolicyError: not authorized `PDF'"
  issues. By contrast, pypdfium2 seems (at least at first) to more
  self-contained and not require any system-tweaking.
- Faster: pypdfium2 appears to render images more quickly than Wand (see
  @cmdlineuser's tests in #899)
- More flexible: pypdfium2 appears to generate images with greater color
  depth; by default, pdfplumber quantizes those images so that they
  save/display compactly (in fact, with smaller file sizes than the
  previous code), this commit also adds parameters to retain all/more of
  the original, more detailed colors.

Thanks to @cmdlineuser in #899 for the suggestion.
2023-07-16 10:46:40 -04:00
Jeremy Singer-Vine ae676aeacd Add PNG-length alternatives to tests 2023-04-20 06:10:42 -04:00
Jeremy Singer-Vine 93f7dbd1a2 Add width & height kwargs to .to_image() #798 2023-02-13 18:49:18 -05:00
Jeremy Singer-Vine b6ff9e8761 Add note to PIL.Image.DecompressionBombError msgs
See https://github.com/jsvine/pdfplumber/issues/413
2022-07-20 15:18:25 -04:00
Jeremy Singer-Vine b98dd7caff Quick fix for image transparency issue 2022-07-18 10:35:35 -04:00
Jeremy Singer-Vine 1a07638ff1 Update test for alt. PNG repr size 2022-07-17 22:58:54 -04:00
Jeremy Singer-Vine 1cd1f9aea9 Change .to_image(...)'s approach ...
... preferring to composite with a white background instead of removing
the alpha channel. This seems to more reliably produce high-quality
conversions (easier to read, fewer conversion artifacts) than either the
prior or other previous approaches.
2022-07-17 22:45:59 -04:00
Jeremy Singer-Vine 063e2edd75 Fix #659 (PageImage.debug_tablefinder())
Thanks to @rneumann7 for flagging!
2022-05-31 15:45:40 -04:00
Jeremy Singer-Vine 1b7458a795 Tweak test_display.py:test__repr_png_ 2022-05-06 13:54:58 -04:00
Jeremy Singer-Vine feb9d082d7 Add final bits of test coverage
Added weak tests for a couple of hard-to-test visual debugging methods
in display.py.

Also marked an exception-handling block in pdf.py as `pragma: nocover`
because we don't yet have a PDF to test it with, but the logic there is
simple and straightforward.
2022-05-06 10:19:48 -04: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
Samkit Jain 02656b29c8 Update tests to bump up test coverage 2020-12-08 22:48:37 +05:30
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 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