Files
fomoPDFMove/main.py

28 lines
1.6 KiB
Python

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)