Optimize thumbnail loading for large PDFs
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user