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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy