Skip to content

Commit

Permalink
Fix broken CroppedPage.annots/hyperlinks
Browse files Browse the repository at this point in the history
Issue was caused by missing `.initial_doctop` and `.rotation`
properties. h/t @Safrone in #1171
  • Loading branch information
jsvine committed Jul 14, 2024
1 parent fc1e671 commit e5737d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pdfplumber/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ def __init__(self, parent_page: Page):
self.pdf = parent_page.pdf
self.page_obj = parent_page.page_obj
self.page_number = parent_page.page_number
self.initial_doctop = parent_page.initial_doctop
self.rotation = parent_page.rotation
self.mediabox = parent_page.mediabox
self.cropbox = parent_page.cropbox
self.flush_cache(Container.cached_properties)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ def test_annots(self):
with pdfplumber.open(path) as pdf:
assert len(pdf.annots)

def test_annots_cropped(self):
pdf = self.pdf_2
page = pdf.pages[0]
assert len(page.annots) == 13
assert len(page.hyperlinks) == 1

cropped = page.crop(page.bbox)
assert len(cropped.annots) == 13
assert len(cropped.hyperlinks) == 1

def test_annots_rotated(self):
def get_annot(filename, n=0):
path = os.path.join(HERE, "pdfs", filename)
Expand Down

0 comments on commit e5737d2

Please sign in to comment.