2 回答
TA贡献1811条经验 获得超4个赞
解决方案是在调用 save 之前设置这些:
page = wi(image=img)
page.background_color = Color('white')
page.alpha_channel = 'remove'
page.save(...)
TA贡献1803条经验 获得超3个赞
这是我的代码:
def convert_pdf(pdf_file):
# Get name file
title = os.path.splitext(os.path.basename(pdf_file))[0]
basename = os.path.basename(pdf_file)
pdf = wi(filename=pdf_file, resolution=100)
pdfImage = pdf.convert("jpg")
outputPath = PATH_IMAGES+"/" + basename
if not os.path.exists(outputPath):
os.mkdir(outputPath)
i=1
for img in pdfImage.sequence:
page = wi(image=img)
page.save(filename=outputPath+"/"+title+"(*page="+str(i)+"*)"+".jpg")
imagePathConverted = outputPath+"/"+title+"(*page="+str(i)+"*)"+".jpg"
'''image = Image.open(imagePathConverted)
if image.mode != 'RGB':
rgb_image = image.convert('RGB')
rgb_image.save(imagePathConverted)'''
i += 1
return outputPath
添加回答
举报
