also replace getPixmap by get_pixmap and getImageData by tobytes

This commit is contained in:
Johannes Schauer Marin Rodrigues 2022-06-27 09:10:58 +01:00
parent c50b44a3a0
commit 8d00b730f1

View file

@ -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()