From fbc31e9c62ed8a14fe8c6831590c0a176c51c0c1 Mon Sep 17 00:00:00 2001 From: Dan Dembinski Date: Thu, 29 Apr 2021 01:03:44 -0400 Subject: [PATCH] Initial commit. Gets PDF size to determine portrait/landscape and resizes to 512 and 128 jgps --- main.py | 28 ++++++++++++++++++++++++++++ required | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 main.py create mode 100644 required diff --git a/main.py b/main.py new file mode 100644 index 0000000..cd1b191 --- /dev/null +++ b/main.py @@ -0,0 +1,28 @@ +import pdf2image + +path = 'C:\\Users\\ddembinski\\Desktop\\' +outputPath = 'C:\\Users\\ddembinski\\Desktop\\thumb\\' +file = 'test.pdf' + +# Gets PDF info, splits the 'Page size' key by the space and sets the width and height values +info = pdf2image.pdfinfo_from_path('C:\\Users\\ddembinski\\Desktop\\test.pdf', poppler_path='c:\\poppler\\bin') +# print(info['Page size'].split(' ')) +width = info['Page size'].split(' ')[0] +height = info['Page size'].split(' ')[2] + +# Landscape +if int(width) > int(height): + images = pdf2image.convert_from_path(path + file, poppler_path='c:\\poppler\\bin', + output_folder=outputPath + '512', single_file=True, + size=(512,None), fmt='jpeg', output_file=file) + images = pdf2image.convert_from_path(path + file, poppler_path='c:\\poppler\\bin', + output_folder=outputPath + '128', single_file=True, + size=(128, None), fmt='jpeg', output_file=file) +# Portrait or square +else: + images = pdf2image.convert_from_path(path + file, poppler_path='c:\\poppler\\bin', + output_folder=outputPath + '512',single_file=True, + size=(None,512), fmt='jpeg', output_file=file) + images = pdf2image.convert_from_path(path + file, poppler_path='c:\\poppler\\bin', + output_folder=outputPath + '128', single_file=True, + size=(None, 128), fmt='jpeg', output_file=file) \ No newline at end of file diff --git a/required b/required new file mode 100644 index 0000000..6c629f7 --- /dev/null +++ b/required @@ -0,0 +1,2 @@ +pdf2image==1.14.0 +Pillow==8.2.0