1

I have a pdf of 6 megs and when I convert it to a set of jpeg images then convert it back to into pdf, the resulting pdf is 48 megs. Even when I used the following code

from PIL import Image
for x in os.listdir(dir1):
    im = Image.open(f'{dir1}{x}')
    im.save(f'{dir2}/{x}', optimize=True, quality=60)

Which optimizes all of my jpeg images, I am only reducing the jpeg file size by 20% that is from about 400K to about 350K. I am not getting the 5X reduction like this person is getting:

How to reduce the image file size using PIL

The code I'm using to convert the pdf to jpg is the following

from pdf2image import convert_from_path
with tempfile.TemporaryDirectory() as path:
    
    images_from_path = convert_from_path(filename, output_folder=path, first_page=0, fmt='jpg')

for e, page in enumerate(images_from_path):
 
    num = e + first_pg
    num = vgf.pad_numbers(num, 3)
    page.save(f"{dest}{long}{num}.jpg", fmt='jpg')
bobsmith76
  • 160
  • 1
  • 9
  • 26

0 Answers0