Skip to content

Commit caddaa7

Browse files
committed
pdf with password
1 parent f31b613 commit caddaa7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

python-tutorials/pdfpassword.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Antes de mais nada -> pip install pypdf2
2+
3+
from PyPDF2 import PdfFileWriter, PdfFileReader
4+
import sys
5+
6+
def password_pdf(file, password):
7+
parser = PdfFileWriter()
8+
pdf = PdfFileReader(file)
9+
10+
for page in range(pdf.numPages):
11+
parser.addPage(pdf.getPage(page))
12+
13+
parser.encrypt(password)
14+
with open(f"pdf_senha_{file}", "wb") as f:
15+
parser.write(f)
16+
f.close()
17+
print(f"pdf_senha_{file} Criado")
18+
19+
if __name__ == "__main__":
20+
file = sys.argv[1]
21+
password = sys.argv[2]
22+
password_pdf(file, password)
23+
24+
# Primeiro chamamos a funcao que voce criou depois o nome do pdf depois a senha que voce quer colocar
25+
# Chamando no terminal python3 pdfpassword.py teste.pdf 123456

0 commit comments

Comments
 (0)