-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert pdf to jpg.py
29 lines (23 loc) · 1.02 KB
/
convert pdf to jpg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pdf2image, os, shutil
from pdf2image import convert_from_path
def convert(fileType):
for file in os.listdir():
if file.endswith(fileType):
images = convert_from_path(file)
for i in range(len(images)):
temp = file.split(fileType) #Delete .pdf from the filename
newFileName = temp[0]
images[i].save(newFileName+ str(i+1) +'.jpg', 'JPEG')
print(file + " has been converted to .jpg file(s)")
def moveTo(fileType, location):
if not os.path.exists(location):
os.mkdir(location)
for file in os.listdir():
if file.endswith(fileType):
print(file + " moved to \""+location+"\"")
shutil.move(file, location)
imageFiles = (".jpg", ".JPG", ".jpeg")
convert(".pdf")
moveTo(imageFiles, "converted")
print("All done!")
input("Press Enter to close this window")