From 8d00b730f1a82d3f5cdba65b79b359237600db9e Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Mon, 27 Jun 2022 09:10:58 +0100 Subject: [PATCH] also replace getPixmap by get_pixmap and getImageData by tobytes --- plakativ.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plakativ.py b/plakativ.py index b63568f..67332c4 100755 --- a/plakativ.py +++ b/plakativ.py @@ -338,12 +338,18 @@ class Plakativ: mat_0 = fitz.Matrix(zoom, zoom) # since pymupdf 1.19.0 a warning will be issued if the deprecated names are used if hasattr(self.doc[self.pagenr], "get_displaylist"): - gdl = self.doc[self.pagenr].get_displaylist + gdl = self.doc[self.pagenr].get_displaylist() else: - gdl = self.doc[self.pagenr].getDisplayList - pix = gdl().getPixmap(matrix=mat_0, alpha=False) - # the getImageData() function was only introduced in pymupdf 1.14.5 + gdl = self.doc[self.pagenr].getDisplayList() + if hasattr(gdl, "get_pixmap"): + pix = gdl.get_pixmap(matrix=mat_0, alpha=False) + else: + pix = gdl.getPixmap(matrix=mat_0, alpha=False) + if hasattr(pix, "tobytes"): + # getImageData was deprecated in pymupdf 1.19.0 + return pix.tobytes("ppm") if hasattr(pix, "getImageData"): + # the getImageData() function was only introduced in pymupdf 1.14.5 return pix.getImageData("ppm") else: # this is essentially the same thing that the getImageData()