Initial commit. Gets PDF size to determine portrait/landscape and resizes to 512 and 128 jgps
This commit is contained in:
28
main.py
Normal file
28
main.py
Normal 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)
|
||||||
Reference in New Issue
Block a user