#pip install PyPDF2
from PyPDF2 import PdfFileWriter, PdfFileReader
import getpass
pdfwriter=PdfFileWriter()
pdf=PdfFileReader('E:\\clcoding.pdf')
for page_num in range(pdf.numPages):
pdfwriter.addPage(pdf.getPage(page_num))
password=getpass.getpass(prompt='Enter Password: ')
pdfwriter.encrypt(password)
with open('E:\\clcoding.pdf','wb') as f:
pdfwriter.write(f)
print("Now File is password protected")
#clcoding.com
Enter Password: ········ Now File is password protected
0 Comments:
Post a Comment