I'm attempting to convert a Jpeg file with, 200 dpi, to a PDF file, however, when I save the file as a PDF I think it's changing the dpi to 72, and thus making the image larger. I had a similar problem when initially trying to scale my jpeg image to a smaller size, and was able to solve that by specifying the dpi when I save the image.
im = Image.open("Image.jpg")
if im.size == (2592, 1728):
out = im.resize((1188,792), Image.ANTIALIAS)
elif im.size == (1728,2592):
out = im.resize((792,1188), Image.ANTIALIAS)
for infile in listing:
outfile = destpath + os.path.splitext(infile) + ".pdf"
current = path + infile
if infile != outfile:
im = Image.open(current)
im.save(outfile, "PDF", Quality = 100)
In the CHANGES file of
PIL 1.1.7 sources one can read:
Added resolution save option for PDF files.
Andreas Kostyrka writes: I've included a patched PdfImagePlugin.py
based on 1.1.6 as included in Ubuntu, that supports a "resolution"
save option. Not great, but it makes the PDF saving more useful by
allowing PDFs that are not exactly 72dpi.
So you should be able to do:
im.save(outfile, "PDF", resolution=100.0)
(seems to work fine on my Ubuntu box).