Reputation: 140
I have a function to convert a bmp to pdf with PILLOW, this script I have it in non compiled version and compiled version (.exe). In the first one it works correctly, but in the second PILLOW throws an exception ('PDF'). Specifically fails in the .save () Paths and filename with extension are correct.
from PIL import Image
def bmp2pdf(self, file):
''' Convert a bmp file to PDF file, and delete old bmp file '''
img = Image.open(file)
output = file.replace('.bmp', '.pdf')
try:
img.save(output, "PDF", resolution=100.0)
remove(file)
except Exception as err:
print(err)
In the compiled version the output is:
'PDF'
Thx.
Upvotes: 1
Views: 885
Reputation: 140
I had to add in my setup to generate the .exe I should import PIL and not PIL.IMAGE, so the whole module is loaded and the pdf feature is available
I'm using cx_freeze:
'Packages': [
'PyQt5.uic',
"...",
'PIL',
]
Upvotes: 1
Reputation: 17408
Follow this code.It works. 3 line code.
from PIL import Image
def bmp2pdf(self,path):
img = Image.open(path)
img.save('image.pdf','pdf')
I got a file named image.pdf with the image in it.
Upvotes: 1