我使用PythonMagick将多页.pdf文件转换为.png文件,但只要.pdf文件的背景透明就失败了。
我的ImageMagick版本是7.0.7-5,Ghostscript版本是9.22
这是我做的:
# just read the first page as an example:
import PythonMagick
im = PythonMagick.Image()
im.density('400') # change dpi
im.read('myfile.pdf[0]') # error occurs
# im.write('target_dir')
然后它将返回错误
RuntimeError: python.exe: iCCP: Not recognizing known sRGB profile that has been edited `C:\Users\...\AppData\Local\Temp\5\magick-19492pMuJsmcrWoca1' @ warning/png.c/MagickPNGWarningHandler/1832
我可以使用以下代码更改背景并避免错误,但我无法使用此方法更改图像dpi:
# just read the first page as an example:
import PythonMagick
im = PythonMagick.Image('myfile.pdf[0]')
im.density('400') # doesn't work
bgColour = '#ffffff'
size = "%sx%s" % (im.columns(), im.rows())
flattened = PythonMagick.Image(size, bgColour)
flattened.type = im.type
flattened.composite(im, 0, 0, PythonMagick.CompositeOperator.SrcOverCompositeOp)
flattened.density('400') # also not working
flattened.write('target_dir')
似乎只要我使用.read()就会返回错误,但更改dpi需要.read()函数。有没有解决方案来读取pdf并更改dpi?