Skip to content

Commit

Permalink
Fix coords for annotations on CroppedPages
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvine committed Aug 4, 2024
1 parent 1496cbd commit b16acc3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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))

Expand Down
7 changes: 4 additions & 3 deletions pdfplumber/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ def parse(annot: T_obj) -> T_obj:
_a, _b, _c, _d = annot["Rect"]
pt0 = rotate_point((_a, _b), self.rotation)
pt1 = rotate_point((_c, _d), self.rotation)
x0, top, x1, bottom = _invert_box(_normalize_box((*pt0, *pt1)), self.height)
rh = self.root_page.height
x0, top, x1, bottom = _invert_box(_normalize_box((*pt0, *pt1)), rh)

a = annot.get("A", {})
extras = {
Expand All @@ -310,9 +311,9 @@ def parse(annot: T_obj) -> T_obj:
"page_number": self.page_number,
"object_type": "annot",
"x0": x0,
"y0": self.height - bottom,
"y0": rh - bottom,
"x1": x1,
"y1": self.height - top,
"y1": rh - top,
"doctop": self.initial_doctop + top,
"top": top,
"bottom": bottom,
Expand Down

0 comments on commit b16acc3

Please sign in to comment.