diff --git a/main.py b/main.py index cd1b191..09d581b 100644 --- a/main.py +++ b/main.py @@ -1,28 +1,54 @@ -import pdf2image +import pdf2image, shutil +from openpyxl import load_workbook -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] +path = 'U:\\CreativeConnectionMove\\Assets\\' +# outputPath = 'C:\\Users\\ddembinski\\Desktop\\thumb\\' +outputPath = 'U:\\thumb\\' -# 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 + +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') diff --git a/required b/required index 6c629f7..e1fee5d 100644 --- a/required +++ b/required @@ -1,2 +1,4 @@ +et-xmlfile==1.1.0 +openpyxl==3.0.7 pdf2image==1.14.0 Pillow==8.2.0