我试图将png文件转换为pdf文件。 PIL
似乎是这样做的,但我在运行时遇到错误(cannot save mode RGBA
)
代码:
import os
import PIL
from PIL import Image
path = 'E:\path_to_file'
filename = '15868799_1.png'
fullpath_filename = os.path.join(path, filename)
im = PIL.Image.open(fullpath_filename)
newfilename = '15868799.pdf'
newfilename_fullpath = os.path.join(path, newfilename)
PIL.Image.Image.save(im, newfilename_fullpath, "PDF", resoultion=100.0)
错误:
File "C:\Python\lib\site-packages\PIL\PdfImagePlugin.py", line 148, in _save
raise ValueError("cannot save mode %s" % im.mode)
ValueError: cannot save mode RGBA