Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5452889

Browse files
Merge pull request avinashkranjan#343 from AmeyaJain-25/pdfEncryption_#339
Script and readme added for PDF Encryption
2 parents b5f3972 + 983108e commit 5452889

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

‎PDF Encryption/pdfEncryption.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# PyPDF2 helps to read, write and many other functionalities with PDF's
2+
# Install PyPDF2 if not in your system.
3+
# Use `pip install PyPDF2` command to install the package from pip installer.
4+
from PyPDF2 import PdfFileWriter, PdfFileReader
5+
6+
print("The file should be in same FOLDER as this script")
7+
8+
pdf_File_Name = input("Enter EXACT name of the PDF in this FOLDER: ")
9+
pdf_File = pdf_File_Name + ".pdf"
10+
11+
# Reading the pdf
12+
pdf = PdfFileReader(pdf_File)
13+
14+
# Object for writing the file
15+
write_Obj = PdfFileWriter()
16+
17+
18+
# Getting the number of pages and writing each page in the writer object
19+
for i in range(pdf.getNumPages()):
20+
page = pdf.getPage(i)
21+
write_Obj.addPage(page)
22+
23+
# Encrypting by the password
24+
owner_Password = input("Enter Password for OWNER: ")
25+
user_Password = input("Enter Password for USER: ")
26+
write_Obj.encrypt(user_pwd=user_Password, owner_pwd=owner_Password, use_128bit=True)
27+
28+
# Naming and creating the encrypted PDF
29+
new_PDF_Name_Input = input("Enter new ENCRYPTED PDF name: ")
30+
new_PDF_Name = new_PDF_Name_Input + '.pdf'
31+
encrypted_PDF = open(new_PDF_Name, 'wb')
32+
write_Obj.write(encrypted_PDF)

‎PDF Encryption/readme.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Python Script for Encrypting the PDF by a Password
2+
The Python Script will let you encrypt the PDF with one OWNER and one USER password respectively. It uses PyPDF2 package to work with the PDF files.
3+
4+
## Setup Instructions
5+
- Download and install Python if not in your local system.
6+
7+
- Downlaod the required packages
8+
```
9+
pip install PyPDF2
10+
```
11+
12+
- To run the script you need to use the following command
13+
```
14+
python pdfEncryption.py
15+
```
16+
17+
- Make sure that the PDF to be encrypted is in that same folder as of this python code file.
18+
19+
## Author
20+
[Ameya Jain](https://github.com/AmeyaJain-25)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /