mirror of
https://github.com/jsvine/pdfplumber.git
synced 2026-08-29 08:34:23 +08:00
Make Page.crop(...) also crop .annots/.hyperlinks
h/t @Safrone in #1171
This commit is contained in:
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. The format
|
||||
### Fixed
|
||||
|
||||
- Fix error on getting `.annots`/`.hyperlinks` from `CroppedPage` (due to missing `.rotation` and `.initial_doctop` attributes) (h/t @Safrone). ([#1171](https://github.com/jsvine/pdfplumber/issues/1171) + [e5737d2](https://github.com/jsvine/pdfplumber/commit/e5737d2))
|
||||
- Fix problem where `Page.crop(...)` was not cropping `.annots/.hyperlinks` (h/t @Safrone). [#1171](https://github.com/jsvine/pdfplumber/issues/1171)
|
||||
- Fix calculation of coordinates for `.annots` on `CroppedPage`s. ([0bbb340](https://github.com/jsvine/pdfplumber/commit/0bbb340))
|
||||
- Dereference structure element attributes (h/t @dhdaines). ([#1169](https://github.com/jsvine/pdfplumber/pull/1169))
|
||||
- Fix `Page.get_attr(...)` so that it fully resolves references before determining whether the attribute's value is `None` (h/t @zzhangyun + @mkl-public). ([#1176](https://github.com/jsvine/pdfplumber/issues/1176))
|
||||
|
||||
+5
-1
@@ -329,7 +329,11 @@ class Page(Container):
|
||||
return parsed
|
||||
|
||||
raw = resolve_all(self.page_obj.annots) or []
|
||||
return list(map(parse, raw))
|
||||
parsed = list(map(parse, raw))
|
||||
if isinstance(self, CroppedPage):
|
||||
return self._crop_fn(parsed)
|
||||
else:
|
||||
return parsed
|
||||
|
||||
@property
|
||||
def hyperlinks(self) -> T_obj_list:
|
||||
|
||||
@@ -69,6 +69,10 @@ class Test(unittest.TestCase):
|
||||
assert len(cropped.annots) == 13
|
||||
assert len(cropped.hyperlinks) == 1
|
||||
|
||||
h0_bbox = pdfplumber.utils.obj_to_bbox(page.hyperlinks[0])
|
||||
cropped = page.crop(h0_bbox)
|
||||
assert len(cropped.annots) == len(cropped.hyperlinks) == 1
|
||||
|
||||
def test_annots_rotated(self):
|
||||
def get_annot(filename, n=0):
|
||||
path = os.path.join(HERE, "pdfs", filename)
|
||||
|
||||
Reference in New Issue
Block a user