Skip to content

Commit

Permalink
Protecting PDF file with password
Browse files Browse the repository at this point in the history
  • Loading branch information
subhayuroy authored Oct 5, 2020
1 parent f8af1a9 commit 357df74
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Protecting PDF/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from PyPDF2 import PdfFileWriter, PdfFileReader

def secure_pdf(file, password):
parser = PdfWriter()
pdf = PdfFileReader(file)
for page in range(pdf.numPages):
parser.addPage(pdf.getPage(page))
parser.encrypt(password)
with open(f"encrypted_{file}", "wb") as f:
parser.write(f)
f.close()
print(f"encrypted_{file} created...")

if __name__=='__main__':
file = "pdf_file_name.pdf"
password = "Password@007"
secure_pdf(file, password)

0 comments on commit 357df74

Please sign in to comment.