import pdf2image, shutil from openpyxl import load_workbook path = 'U:\\CreativeConnectionMove\\Assets\\' # outputPath = 'C:\\Users\\ddembinski\\Desktop\\thumb\\' outputPath = 'U:\\thumb\\' wb = load_workbook('fomoPDFs.xlsx') sh1 = wb.get_sheet_by_name('Sheet1') sh2 = wb.get_sheet_by_name('Failed') failedrow = 2 for row in sh1.iter_rows(min_row=2): file = row[3].value outfile = row[2].value print(row[0].value) # Gets PDF info, splits the 'Page size' key by the space and sets the width and height values try: info = pdf2image.pdfinfo_from_path(path + file, poppler_path='c:\\poppler\\bin') # print(info['Page size'].split(' ')) width = info['Page size'].split(' ')[0] height = info['Page size'].split(' ')[2] # Landscape if float(width) > float(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=outfile) 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=outfile) # 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=outfile) 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=outfile) shutil.copy(path + file, outputPath + 'PDF\\' + outfile + '.pdf') except: print('%s - %s conversion failed' % (row[0].value, row[3].value)) sh2.cell(row=failedrow, column=1).value = row[0].value sh2.cell(row=failedrow, column=2).value = row[2].value sh2.cell(row=failedrow, column=3).value = row[3].value failedrow = failedrow + 1 wb.save('fomoPDFs.xlsx')