|
|
|
|
@@ -1,13 +1,17 @@
|
|
|
|
|
import pdf2image, shutil, sys, os
|
|
|
|
|
import pdf2image, shutil, sys, os, logging
|
|
|
|
|
|
|
|
|
|
file = sys.argv[1]
|
|
|
|
|
outfile = os.path.basename(file)
|
|
|
|
|
outfile = os.path.splitext(os.path.basename(file))[0]
|
|
|
|
|
#outputPath = 'C:\\Images\\IDV2ICP\\'
|
|
|
|
|
outputPath = 'C:\\Users\\ddembinski\\Desktop\\FOMO\\'
|
|
|
|
|
uploadPath = os.path.dirname(file)
|
|
|
|
|
|
|
|
|
|
logging.basicConfig(filename='ICPThumbnails.log', format='%(asctime)s - %(message)s',
|
|
|
|
|
datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
# Gets PDF info, splits the 'Page size' key by the space and sets the width and height values
|
|
|
|
|
try:
|
|
|
|
|
info = pdf2image.pdfinfo_from_path(file, poppler_path='c:\\poppler\\bin')
|
|
|
|
|
# print(info['Page size'].split(' '))
|
|
|
|
|
width = info['Page size'].split(' ')[0]
|
|
|
|
|
height = info['Page size'].split(' ')[2]
|
|
|
|
|
|
|
|
|
|
@@ -15,7 +19,7 @@ try:
|
|
|
|
|
# Landscape
|
|
|
|
|
if float(width) > float(height):
|
|
|
|
|
images = pdf2image.convert_from_path(file, poppler_path='c:\\poppler\\bin',
|
|
|
|
|
output_folder=outputPath + '512', single_file=True,
|
|
|
|
|
output_folder=outputPath + '256', single_file=True,
|
|
|
|
|
size=(512,None), fmt='jpeg', output_file=outfile)
|
|
|
|
|
images = pdf2image.convert_from_path(file, poppler_path='c:\\poppler\\bin',
|
|
|
|
|
output_folder=outputPath + '128', single_file=True,
|
|
|
|
|
@@ -23,12 +27,21 @@ try:
|
|
|
|
|
# Portrait or square
|
|
|
|
|
else:
|
|
|
|
|
images = pdf2image.convert_from_path(file, poppler_path='c:\\poppler\\bin',
|
|
|
|
|
output_folder=outputPath + '512',single_file=True,
|
|
|
|
|
output_folder=outputPath + '256',single_file=True,
|
|
|
|
|
size=(None,512), fmt='jpeg', output_file=outfile)
|
|
|
|
|
images = pdf2image.convert_from_path(file, poppler_path='c:\\poppler\\bin',
|
|
|
|
|
output_folder=outputPath + '128', single_file=True,
|
|
|
|
|
size=(None, 128), fmt='jpeg', output_file=outfile)
|
|
|
|
|
shutil.move(file, outputPath + 'PDF\\' + str(outfile))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.isdir(uploadPath + '\\Archive'):
|
|
|
|
|
os.mkdir(uploadPath + '\\Archive')
|
|
|
|
|
shutil.move(file, uploadPath + '\\Archive\\' + str(outfile) + '.pdf')
|
|
|
|
|
|
|
|
|
|
logging.info('%s - Converted' % (file))
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print('%s - conversion failed' % (file))
|
|
|
|
|
print(e)
|
|
|
|
|
logging.info('%s - conversion failed' % (file))
|
|
|
|
|
if not os.path.isdir(uploadPath + '\\Exception'):
|
|
|
|
|
os.mkdir(uploadPath + '\\Exception')
|
|
|
|
|
shutil.move(file, uploadPath + '\\Exception\\' + str(outfile) + '.pdf')
|