【问题标题】:PyMuPDF Pixmap tobytes() returns attribute errorPyMuPDF Pixmap tobytes() 返回属性错误
【发布时间】:2021-05-18 23:39:09
【问题描述】:

我正在关注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'

文档示例:

这可能是什么问题?

【问题讨论】:

    标签: python pymupdf


    【解决方案1】:

    我是 PyMuPDF 的维护者。 你的配置是什么?我刚刚使用 v1.18.13 在 Windows 和 Linux 上尝试了您的代码,并且可以正常工作。

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

    窗户:

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

    【讨论】:

    • 我不确定问题是什么,但我最终使用了pix.pil_tobytes(),它有效。我也在使用 python 3.8 的 ubuntu。无论如何感谢您的帮助@JorjMckie
    • PyMuPDF 中的重命名工作让旧名称在某些版本中作为已弃用的别名继续存在。所以你也应该暂时摆脱pix.getPNGdata()pix.detPNGData()——不管你的地方出了什么问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-12
    • 2014-08-19
    相关资源
    最近更新 更多