mirror of
https://github.com/jsvine/pdfplumber.git
synced 2026-08-29 08:34:23 +08:00
Remove confusion about kwargs passed to wand.Image
Thanks to @pseudomonas in #798 for flagging. Decided to go for a stricter approach, given the complexity of getting a more flexible approach right. But open to PRs that provide the more flexible approach.
This commit is contained in:
@@ -115,7 +115,7 @@ The `pdfplumber.Page` class is at the core of `pdfplumber`. Most things you'll d
|
||||
|`.extract_words(x_tolerance=3, y_tolerance=3, keep_blank_chars=False, use_text_flow=False, horizontal_ltr=True, vertical_ttb=True, extra_attrs=[], split_at_punctuation=False)`| Returns a list of all word-looking things and their bounding boxes. Words are considered to be sequences of characters where (for "upright" characters) the difference between the `x1` of one character and the `x0` of the next is less than or equal to `x_tolerance` *and* where the `doctop` of one character and the `doctop` of the next is less than or equal to `y_tolerance`. A similar approach is taken for non-upright characters, but instead measuring the vertical, rather than horizontal, distances between them. The parameters `horizontal_ltr` and `vertical_ttb` indicate whether the words should be read from left-to-right (for horizontal words) / top-to-bottom (for vertical words). Changing `keep_blank_chars` to `True` will mean that blank characters are treated as part of a word, not as a space between words. Changing `use_text_flow` to `True` will use the PDF's underlying flow of characters as a guide for ordering and segmenting the words, rather than presorting the characters by x/y position. (This mimics how dragging a cursor highlights text in a PDF; as with that, the order does not always appear to be logical.) Passing a list of `extra_attrs` (e.g., `["fontname", "size"]` will restrict each words to characters that share exactly the same value for each of those [attributes](https://github.com/jsvine/pdfplumber/blob/develop/README.md#char-properties), and the resulting word dicts will indicate those attributes. Setting `split_at_punctuation` to `True` will enforce breaking tokens at punctuations specified by `string.punctuation`; or you can specify the list of separating punctuation by pass a string, e.g., <code>split_at_punctuation='!"&\'()*+,.:;<=>?@[\]^\`\{\|\}~'</code>. |
|
||||
|`.search(pattern, regex=True, case=True, **kwargs)`|*Experimental feature* that allows you to search a page's text, returning a list of all instances that match the query. For each instance, the response dictionary object contains the matching text, any regex group matches, the bounding box coordinates, and the char objects themselves. `pattern` can be a compiled regular expression, an uncompiled regular expression, or a non-regex string. If `regex` is `False`, the pattern is treated as a non-regex string. If `case` is `False`, the search is performed in a case-insensitive manner. The remaining `**kwargs` are those you would pass to `.extract_text(layout=True, ...)`.|
|
||||
|`.extract_tables(table_settings)`| Extracts tabular data from the page. For more details see "[Extracting tables](#extracting-tables)" below.|
|
||||
|`.to_image(**conversion_kwargs)`| Returns an instance of the `PageImage` class. For more details, see "[Visual debugging](#visual-debugging)" below. For conversion_kwargs, see [here](http://docs.wand-py.org/en/latest/wand/image.html#wand.image.Image).|
|
||||
|`.to_image(resolution=72)`| Returns an instance of the `PageImage` class, at `resolution` pixels per inch. For more details, see "[Visual debugging](#visual-debugging)" below. |
|
||||
|`.close()`| By default, `Page` objects cache their layout and object information to avoid having to reprocess it. When parsing large PDFs, however, these cached properties can require a lot of memory. You can use this method to flush the cache and release the memory. (In version `<= 0.5.25`, use `.flush_cache()`.)|
|
||||
|
||||
### Objects
|
||||
|
||||
+2
-5
@@ -368,17 +368,14 @@ class Page(Container):
|
||||
p._objects["char"] = utils.dedupe_chars(self.chars, **kwargs)
|
||||
return p
|
||||
|
||||
def to_image(self, **conversion_kwargs: Any) -> "PageImage":
|
||||
def to_image(self, resolution: Optional[int] = None) -> "PageImage":
|
||||
"""
|
||||
For conversion_kwargs, see:
|
||||
http://docs.wand-py.org/en/latest/wand/image.html#wand.image.Image
|
||||
"""
|
||||
from .display import DEFAULT_RESOLUTION, PageImage
|
||||
|
||||
kwargs = dict(conversion_kwargs)
|
||||
if "resolution" not in conversion_kwargs:
|
||||
kwargs["resolution"] = DEFAULT_RESOLUTION
|
||||
return PageImage(self, **kwargs)
|
||||
return PageImage(self, resolution=resolution or DEFAULT_RESOLUTION)
|
||||
|
||||
def to_dict(self, object_types: Optional[List[str]] = None) -> Dict[str, Any]:
|
||||
if object_types is None:
|
||||
|
||||
Reference in New Issue
Block a user