I am trying to convert a jpeg file with 200 dpi to a pdf file, however, when I save the file in PDF format, I think it changes the dpi to 72 and thus makes the image larger. I had a similar problem when I initially tried to scale the jpeg image to a smaller size and was able to solve this by specifying dpi when saving the image.
im = Image.open("Image.jpg")
dpi=im.info['dpi']
if im.size == (2592, 1728):
out = im.resize((1188,792), Image.ANTIALIAS)
elif im.size == (1728,2592):
out = im.resize((792,1188), Image.ANTIALIAS)
out.save(project, dpi=dpi)
Now when I try to save this jpeg as a PDF, dpi is not like the difference, and I get an image that is larger than my original, it looks like it has a lower dpi. Is there a way to provide consistent resolution when converting from Jpeg to PDF using PIL? Or is there a better way for me to do this?
This is what I have to convert the file directory from jpeg to pdf:
for infile in listing:
outfile = destpath + os.path.splitext(infile)[0] + ".pdf"
current = path + infile
if infile != outfile:
im = Image.open(current)
dpi=im.info['dpi']
im.save(outfile, "PDF", Quality = 100)
!