简体   繁体   English

使用 PyMuPDF 将 PDF 页面 Pixmap 保存为 PNG 时出现颜色问题

[英]Color issue when saving PDF page Pixmap as PNG using PyMuPDF

I'm running the following bit of Python code from the PyMuPDF 1.16.17 documentation, which save PNG images for every page in a PDF file.我正在运行 PyMuPDF 1.16.17 文档中的 Python 代码的以下位,它为 PDF 文件中的每一页保存 PNG 图像。

import sys, fitz  # import the binding
fname = "test.pdf" # get filename from command line
doc = fitz.open(fname)  # open document
for page in doc:  # iterate through the pages
    pix = page.getPixmap()
    pix.writePNG("F:/cynthia/page-%i.png" % page.number)  # store image as a PNG

The resulting PNG images' colors are off from the PDF originals (too saturated and high contrast).生成的 PNG 图像的 colors 与 PDF 原件不同(太饱和且对比度太高)。 I know function Page.getPixmap() has a "colorspace" argument, and using Document.getPageImageList I found out that my PDF's colorspace is "DeviceCMYK".我知道 function Page.getPixmap()有一个“颜色空间”参数,并且使用Document.getPageImageList我发现我的 PDF 的颜色空间是“DeviceCMYK”。 But when I try to get a Pixmap using CMYK as colorspace (replacing the pix = page.getPixmap() line with pix = page.getPixmap(colorspace="CMYK") or `pix = page.getPixmap(colorspace=csCMYK)), it doesn't change the resulting colors.但是,当我尝试使用 CMYK 作为颜色空间获取 Pixmap 时(用pix = page.getPixmap(colorspace="CMYK")或 `pix = page.getPixmap(colorspace=csCMYK) 替换pix = page.getPixmap()行),它不会改变生成的 colors。 Any help is appreciated.任何帮助表示赞赏。

Please upgrade your PyMuPDF version.请升级您的 PyMuPDF 版本。 Then ICC color support will be included which should improve your output.然后将包括 ICC 颜色支持,这将改善您的 output。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM