2 回答

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊
解決方案是在調(diào)用 save 之前設(shè)置這些:
page = wi(image=img)
page.background_color = Color('white')
page.alpha_channel = 'remove'
page.save(...)

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
這是我的代碼:
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
添加回答
舉報(bào)