Converting Png To Pdf With PIL Save Mode Error
Im trying to convert png files into pdf's. PIL seems to be the way to do it but Im getting an error (cannot save mode RGBA) when running it Code: import os import PIL from PIL impo
Solution 1:
You need to convert your PNG from RGBA to RGB first.
Sample code:
from PIL import Image
PNG_FILE = 'E:\path_to_file\15868799_1.png'
PDF_FILE = 'E:\path_to_file\15868799.pdf'
rgba = Image.open(PNG_FILE)
rgb = Image.new('RGB', rgba.size, (255, 255, 255)) # white background
rgb.paste(rgba, mask=rgba.split()[3]) # paste using alpha channel as mask
rgb.save(PDF_FILE, 'PDF', resoultion=100.0)
Post a Comment for "Converting Png To Pdf With PIL Save Mode Error"