Skip to content

Commit

Permalink
Remove transparent link annots from pdfdoc
Browse files Browse the repository at this point in the history
Transparent link annotations will not be visible in the thumbnails.
Removing them will lower memory usage.

Close #341
  • Loading branch information
kbengs authored and jeromerobert committed Oct 24, 2021
1 parent 635a6fb commit 75fa6cc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pdfarranger/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,23 @@ def __init__(self, filename, basename, tmp_dir, parent):
else:
raise PDFDocError(_("File is neither pdf nor image"))

self.transparent_link_annots_removed = [False] * self.document.get_n_pages()

def get_page(self, n_page):
"""Get a page where transparent link annotations are removed.
By removing them memory usage will be lower.
"""
page = self.document.get_page(n_page)
if self.transparent_link_annots_removed[n_page]:
return page
annot_mapping_list = page.get_annot_mapping()
for annot_mapping in annot_mapping_list:
a = annot_mapping.annot
if a.get_annot_type() == Poppler.AnnotType.LINK and a.get_color() is None:
page.remove_annot(a)
self.transparent_link_annots_removed[n_page] = True
return page

class PageAdder:
"""Helper class to add pages to the current model."""
Expand Down Expand Up @@ -495,7 +512,7 @@ def update(self, p, ref, scale, resample, is_preview):
thumbnail = p.preview
else:
pdfdoc = self.pdfqueue[p.nfile - 1]
page = pdfdoc.document.get_page(p.npage - 1)
page = pdfdoc.get_page(p.npage - 1)
w, h = page.get_size()
thumbnail = cairo.ImageSurface(
cairo.FORMAT_ARGB32, int(0.5 + w * scale), int(0.5 + h * scale)
Expand Down

0 comments on commit 75fa6cc

Please sign in to comment.