我正在关注the documentation并使用最新的 PyMuPDF (1.18.13)。但是 Pixmap.tobytes()
对我不起作用:
zoom = 2 # zoom factor
mat = fitz.Matrix(zoom, zoom)
pix = page.getPixmap(matrix = mat)
stream = pix.tobytes(output="png")
AttributeError: 'Pixmap' object has no attribute 'tobytes'
这里可能存在什么问题?
最佳答案
我是 PyMuPDF 的维护者。 你的配置是什么?我刚刚在 Windows 和 Linux 上分别使用 v1.18.13 尝试了您的代码,并且它可以工作。
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fitz
>>> fitz.version
('1.18.13', '1.18.0', '20210505063222')
>>> doc=fitz.open("v110-changes.pdf")
>>> page=doc[0]
>>> pix=page.get_pixmap()
>>> b=pix.tobytes()
>>>
Windows:
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fitz
>>> fitz.version
('1.18.13', '1.18.0', '20210505063222')
>>> doc=fitz.open("v110-changes.pdf")
>>> page=doc[0]
>>> pix=page.get_pixmap()
>>> b = pix.tobytes()
>>>
关于python - PyMuPDF Pixmap tobytes() 返回属性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67595196/