Optimize thumbnail loading for large PDFs

This commit is contained in:
2026-06-29 18:35:48 +08:00
parent 060017b417
commit 68eef25ea7
4 changed files with 79 additions and 13 deletions
+13 -1
View File
@@ -65,6 +65,10 @@ class PdfDocument:
def is_dirty(self) -> bool:
return self._dirty
@property
def revision(self) -> int:
return self._revision
def open(self, path: str | Path, password: str | None = None) -> None:
self.close()
self.path = Path(path)
@@ -114,7 +118,15 @@ class PdfDocument:
page = self._page(page_index)
rect = page.rect
zoom = width / rect.width
thumbnail = self.render_page(page_index, zoom)
pixmap = page.get_pixmap(matrix=fitz.Matrix(zoom, zoom), alpha=False)
image = QImage(
pixmap.samples,
pixmap.width,
pixmap.height,
pixmap.stride,
QImage.Format.Format_RGB888,
)
thumbnail = image.copy()
self._remember_cache_item(self._thumbnail_cache, cache_key, thumbnail, max_items=80)
return thumbnail.copy()