Commit Graph

173 Commits

Author SHA1 Message Date
Jeremy Singer-Vine 6e769ea66d Rerun upgrade code-formatting libraries 2024-08-07 10:40:57 -04:00
Jeremy Singer-Vine 9025c3fc56 Fix object coordinates when mediabox != (0,0,...)
See issue #1181 for details.
2024-08-05 12:28:42 -04:00
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 1496cbda7d Add return_chars=True kwarg to Page.extract_words
h/t @cmdlineluser in #1173
2024-08-04 11:14:07 -04:00
Jeremy Singer-Vine d39302fa2c Add Table.columns, analogous to Table.rows (#1050)
h/t @Pk13055 for the suggestion
2024-08-02 19:00:23 -04:00
Jeremy Singer-Vine 48cab3f73e Change default .repair(...) setting h/t @Laubeee
Now passes "default" rather than "prepress" to Ghostscript's
`-dPDFSETTINGS` parameter.

Also makes that setting modifiable via `.repair(setting=...)`, where the
value is one of `"default"`, `"prepress"`, `"printer"`, or `"ebook"`.

See #874 and https://ghostscript.com/docs/9.54.0/VectorDevices.htm
2024-07-31 18:16:00 -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
QAN 1f57556201 use extra_attrs 2024-07-02 15:01:57 +02:00
QAN 76752c4a31 add ignore_char_properties arg in dedup_chars 2024-06-27 11:40:35 +02:00
Jeremy Singer-Vine 4daf0aa1b9 Handle PDFDocEncoding failures in decode_text
Fixes issue #1147
2024-06-11 16:21:45 -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 147f2c4c07 Merge branch 'develop' of github.com:jsvine/pdfplumber into develop 2024-03-07 07:52:19 -05:00
Jeremy Singer-Vine 850fd45b02 Add {line,char}_dir{,rotated,render} params
... and in the process, deeply rewrite the text extraction code to be
more flexible with regards to reading/writing non top-to-bottom,
left-to-right text.

Major kudos and thanks to @afriedman412 for the initial idea, initial
prototype, and inspiration for these new features.

Breaking change: word["direction"] is no longer {1,-1} but instead
{"ltr","rtl","ttb","btt"}.

Deprecated: Text-extraction parameters `horizontal_ltr` and
`vertical_ttb`.
2024-03-06 20:53:03 -05:00
Jeremy Singer-Vine 1820247309 Add curve["path"] and curve["dash"]
... now that they're available in the latest pdfminer.six
2024-03-03 14:10:47 -05:00
David Huggins-Daines 207312eae7 Some utility methods for logical structure (#1095) 2024-03-02 19:44:40 -05:00
David Huggins-Daines 3e74fb134f fix: handle missing ParentTree 2024-02-14 08:52:56 -05:00
David Huggins-Daines 7322077e0f fix: placate flake8 2024-02-05 08:53:03 -05:00
David Huggins-Daines f3d20fcf35 fix: prevent pypdfium2 file leak (fixes: #1089) 2024-02-05 08:52:51 -05: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 fff846b073 Merge pull request #1041 from afriedman412/x_tolerance_ratio
Add `x_tolerance_ratio` param to `extract_text` and similar functions
2023-11-09 15:18:27 -05:00
Jeremy Singer-Vine 35ed9e0695 Merge pull request #963 from dhdaines/structure_tree
Support for PDF 1.3 logical structure
2023-11-09 15:08:09 -05:00
Jeremy Singer-Vine 0145647c58 Add x_tolerance_ratio test for extract_words(...) 2023-11-08 15:36:42 -05:00
Andy Friedman 1359fad7c0 adding x_tolerance_ratio functionality 2023-11-04 16:33:11 -04:00
Andy Friedman 9af84e2b5e Revert "linting"
This reverts commit c2564653e8.
2023-11-02 11:27:35 -04:00
Andy Friedman c2564653e8 linting 2023-11-01 16:13:56 -04:00
Andy Friedman 5a85ab7a0c add x_tolerance_ratio 2023-11-01 13:54:10 -04:00
Jeremy Singer-Vine 0bfffc2448 Fix Page.get_textmap caching for extra_attrs=[...]
... by preconverting list kwargs to tuples.
2023-10-27 10:53:17 -04:00
David Huggins-Daines ed707a7ec6 fix: respect use_text_flow in extract_text (fixes #982) 2023-09-06 15:51:50 -04:00
David Huggins-Daines 036044d92e fix: handle more MCR/OBJR madness 2023-09-05 23:47:23 -04:00
David Huggins-Daines 14f9a67c66 fix: complete coverage and fix handling of OBJR/MCR 2023-09-05 23:03:17 -04:00
David Huggins-Daines 8d485c38cd test: trivial synthetic pdf for completing structure coverage 2023-09-05 23:03:03 -04:00
David Huggins-Daines 183d5a840b feat: add --structure-text, like pdfinfo -struct-text (but better) 2023-08-19 10:00:28 -06:00
David Huggins-Daines 3c83366d9d feat: extract structure tree from pages or documents 2023-08-19 09:49:48 -06:00
David Huggins-Daines 142fc90cc5 Support for marked content section IDs (#961) 2023-08-19 11:29:21 -04:00
Jeremy Singer-Vine f6887b5b33 Add gs_path argument to .open(...) & .repair(...) 2023-08-06 17:24:00 -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 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 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 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 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 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 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 ae676aeacd Add PNG-length alternatives to tests 2023-04-20 06:10:42 -04:00