-
Notifications
You must be signed in to change notification settings - Fork 727
/
imges2pdf.py
27 lines (21 loc) · 929 Bytes
/
imges2pdf.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
import PyPDF2
from os import path
import sys
def File_existance_checker(filePath):
if path.isfile(filePath):
return filePath
else:
print("[-] Provide a valid File")
sys.exit(1)
pdf_stored_path=input("Enter the name of you pdf file (please use backslash when typing in directory path):")
textFile_stored_path=path.join(path.dirname(pdf_stored_path),path.basename(pdf_stored_path).replace(".pdf",".txt"))
pdf_stored_path=File_existance_checker(pdf_stored_path)
print(textFile_stored_path)
with open(pdf_stored_path,'rb') as pdf_object:
pdf_read=PyPDF2.PdfFileReader(pdf_object)
pdf_pages=pdf_read.numPages
for i in range(pdf_pages):
page_object=pdf_read.getPage(i)
with open(textFile_stored_path,'a+') as f:
f.write((page_object.extract_text()))
print(f"[+] Pdf Text has been extracted and written to {path.basename(textFile_stored_path)}")