8000 Add ch13 section 5 exercise 2 solution · arbi11/python-basics-exercises@5041815 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5041815

Browse files
committed
Add ch13 section 5 exercise 2 solution
1 parent 56b6289 commit 5041815

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

ch13-interact-with-pdf-files/5-encrypting-and-decrypting-pdfs.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,19 @@
2727
output_path = Path.home() / "top_secret_encrypted.pdf"
2828
with output_path.open(mode="wb") as output_file:
2929
pdf_writer.write(output_file)
30+
31+
32+
# ***********
33+
# Exercise 2
34+
#
35+
# Open the `top_secret_encrpyted.pdf` file you created in exercise 1,
36+
# decrypt it, and print the text on the first page of the PDF.
37+
# ***********
38+
39+
pdf_path = Path.home() / "top_secret_encrypted.pdf"
40+
pdf_reader = PdfFileReader(str(pdf_path))
41+
42+
pdf_reader.decrypt("Unguessable")
43+
44+
first_page = pdf_reader.getPage(0)
45+
print(first_page.extractText())

0 commit comments

Comments
 (0)
0