Initial commit. Gets PDF size to determine portrait/landscape and resizes to 512 and 128 jgps

This commit is contained in:
Dan Dembinski
2021-04-29 01:03:44 -04:00
commit fbc31e9c62
2 changed files with 30 additions and 0 deletions

28
main.py Normal file
View File

@@ -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)