Commit Graph

615 Commits

Author SHA1 Message Date
Jeremy Singer-Vine 2429fd7bf3 Merge pull request #983 from dhdaines/issue-982
Respect `use_text_flow` in `extract_text`
2023-09-11 12:13:58 -04:00
David Huggins-Daines ed707a7ec6 fix: respect use_text_flow in extract_text (fixes #982) 2023-09-06 15:51:50 -04:00
Jeremy Singer-Vine 336f83f6da Update CHANGELOG.md 2023-08-19 11:40:55 -04:00
Jeremy Singer-Vine 4a76a1f3a5 Add hyperlinks and experimentality to mcid/tag notes 2023-08-19 11:38:39 -04:00
David Huggins-Daines 142fc90cc5 Support for marked content section IDs (#961) 2023-08-19 11:29:21 -04:00
Jeremy Singer-Vine d8b9c1581a Merge branch 'stable' into develop 2023-08-12 17:05:44 -04:00
Jeremy Singer-Vine 94da66c1b3 Add thanks to @jeremybmerrill 2023-08-12 17:05:21 -04:00
Jeremy B. Merrill 41498312a0 Update form-parsing example in README (#958)
Thanks to PR from @jeremybmerrill, who writes:

> This form-parsing example handles form fields recursively contained within other form fields, removes the incorrect-assumption that field-names are unique and includes the alternate field name in output (which is often a very useful guide to what's in a field).

> the prior form-parsing example used the field-name ("T" entry) as the key in the form_data dict, implicitly assuming that the field name is globally unique within a document. That's not a correct assumption; nested field names are often simply a numeric index like 1 or 0. The prior example also entirely ignored the TU entry alternate field name.
2023-08-12 17:03:39 -04:00
Jeremy Singer-Vine f6887b5b33 Add gs_path argument to .open(...) & .repair(...) 2023-08-06 17:24:00 -04:00
Jeremy Singer-Vine 7c2d46b4a1 Fix some CHANGELOG.md formatting 2023-07-29 15:05:54 -04:00
Jeremy Singer-Vine 87d5b4a3b1 Merge pull request #951 from jsvine/develop
Merge v0.10.2
2023-07-29 15:03:00 -04:00
Jeremy Singer-Vine f92a687f25 Bump to v0.10.2 v0.10.2 2023-07-29 14:52:50 -04:00
Jeremy Singer-Vine 267ec8a5d7 Update CHANGELOG.md 2023-07-29 14:51:38 -04:00
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 7af3d0fa96 Merge pull request #946 from dhdaines/iterable_geometry
Accept Iterable for geometry utils (fixes #945)
2023-07-28 14:46:16 -04:00
David Huggins-Daines 9014a2939f fix: upgrade mypy to avoid erroneous errors
See https://github.com/python/mypy/issues/13627 (among others)
2023-07-25 16:14:22 -04:00
David Huggins-Daines 72c3a0efde fix: isort 2023-07-25 16:10:46 -04:00
David Huggins-Daines 53bee23e5a feat: accept Iterable for geometry utils.
Note: this removes the fragile-looking type manipulation in intersects_bbox as
making it work with iterables is very ugly and I am not convinced of its
usefulness
2023-07-24 10:15:34 -04:00
Jeremy Singer-Vine 28f4ebeb3c Use pdfium's *public* (not private) render method
Thanks to @mara004 for flagging here:
https://github.com/jsvine/pdfplumber/discussions/899#discussioncomment-6520928
2023-07-23 18:19:50 -04:00
Jeremy Singer-Vine 90742bdcbc Bump to v0.10.1 v0.10.1 2023-07-19 08:58:41 -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 f3c628ab54 Fix bug-report link to docs/repairing.md 2023-07-16 23:01:35 -04:00
Jeremy Singer-Vine 00386ad8ca Merge pull request #936 from jsvine/develop
v0.10.0
v0.10.0
2023-07-16 18:35:42 -04:00
Jeremy Singer-Vine 28c0afc35c Fix missing trailing parens in CHANGELOG.md 2023-07-16 18:30:29 -04:00
Jeremy Singer-Vine ab9164ba19 Update CITATION.cff 2023-07-16 18:25:36 -04:00
Jeremy Singer-Vine 9aa57dece4 Update CHANGELOG.md 2023-07-16 18:23:36 -04:00
Jeremy Singer-Vine c9d24d50b0 Remove support for Python 3.7 2023-07-16 18:22:58 -04:00
Jeremy Singer-Vine 34070b4985 Update .github/workflows/tests.yml 2023-07-16 18:10:14 -04:00
Jeremy Singer-Vine 00efbf02df Update pandas version in requirements-dev 2023-07-16 18:08:42 -04:00
Jeremy Singer-Vine b5c268d756 Fix PNG size tests for other platforms 2023-07-16 17:51:53 -04:00
Jeremy Singer-Vine 10ae47d024 Fix tuple/Tuple typesig for earlier Python versions 2023-07-16 17:45:24 -04:00
Jeremy Singer-Vine fbc6fac02f Merge branch 'develop' of github.com:jsvine/pdfplumber into develop 2023-07-16 17:39:43 -04:00
Jeremy Singer-Vine 70c25babf3 Bump to v0.10.0 2023-07-16 17:38:34 -04:00
Jeremy Singer-Vine 0cc1047816 Update CHANGELOG.md for v0.10.0 2023-07-16 17:34:35 -04:00
Jeremy Singer-Vine de65bd8698 Update examples 2023-07-16 17:33:25 -04:00
Jeremy Singer-Vine 3ab6649c03 Add repair notes to docs and bug report template 2023-07-16 17:18:46 -04:00
Jeremy Singer-Vine db6ae97bfb Add pdfplumber.repair(...) and .open(repair=True)
This commit adds convenience methods to repair PDFs on the fly and/or to
write repaired PDFs to disk.

Currently, this does so via Ghostscript using the method we've asked
many users to try by following the instructions at
https://superuser.com/questions/278562/how-can-i-fix-repair-a-corrupted-pdf-file

Now, hopefully, this saves folks a few steps.
2023-07-16 17:07:42 -04:00
Jeremy Singer-Vine df0e027fc7 Remove tox from setup.cfg 2023-07-16 15:41:44 -04:00
Jeremy Singer-Vine 788857ed03 Add Python 3.11 to supported versions 2023-07-16 15:40:52 -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 ea5e2753df Move expanded notes on colors to docs/colors.md 2023-07-14 12:21:19 -04:00
Jeremy Singer-Vine 6d62054ffa Remove vestigial 'font' and 'name' properties 2023-07-14 12:01:28 -04:00
Jeremy Singer-Vine 97ca4b0bf3 Extract and handle patterns + (some) color spaces
Inspired by https://github.com/jsvine/pdfplumber/issues/828

The PDF reference allows for "colors" to be defined as a series of
numbers and/or (much less commonly) patterns.

(See p. 288 and section 4.6 here:
https://ghostscript.com/~robin/pdf_reference17.pdf)

This commit separates out the pattern component of colors into their own
attributes, `stroking_pattern` and `non_stroking_pattern` so that they
don't muddle the interpretation of standard colors' tuple-of-numbers
representation.

This commit also adds code that attempts to fetch the `ncs`/`scs` color
space of each object. Due to current limitations of pdfminer.six,
however, the only such color space immediately available is the `ncs`
(non-stroking color space) property of char objects.
2023-07-04 11:24:55 -04:00
Jeremy Singer-Vine 3772af60c7 Add Page.find_table(...) (#873)
Previously, `pdfplumber.Page` had these table-getting methods:

- `.find_tables(...)`
- `.extract_tables(...)`
- `.extract_table(...)`

For consistency/completeness's sake, this commit adds:

- `.find_table(...)`

... which, analogous to `.extract_table(...)`, returns the largest table
on the page.

Indeed, `.extract_table(...)` now uses `.find_table(...)` beneath the
hood.

Thanks to @pdille for the suggestion, here:
https://github.com/jsvine/pdfplumber/discussions/864#discussioncomment-5668209
2023-07-04 09:59:00 -04: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 474f74c906 Add another test for use_text_flow 2023-07-01 18:41:58 -04:00
Jeremy Singer-Vine a032019a97 Rewrite char_begins_new_word for ease & edge cases
Main edge-case was with `use_text_flow` on text-lines that then
backtracked. But this rewrite also aims to make the logic more explicit
and easier to follow.
2023-07-01 18:40:11 -04:00
Jeremy Singer-Vine b1db5b840f Handle use_text_flow more consistently
As noted in #912, `use_text_flow` was not being handled consistently, as
characters and words were being re-sorted without checking first if this
parameter was set to `True`.
2023-07-01 18:36:59 -04:00
Jeremy Singer-Vine 5aaabcd038 Merge pull request #877 from RitchieP/patch-1
Update README.md
2023-05-08 22:27:42 +02:00