I would like to know which pages are encrypted of a pdf document. I would like to know this, because some pdf documents are merged where one document had encryption and the other not. So this means some pages were not encrypted. Here I'm trying to create a reproducible code with doc_not_encrypted.pdf
and doc_is_encrypted.pdf
:
import pypdf
File = open("doc_not_encrypted.pdf", "rb")
reader = pypdf.PdfReader(File)
if reader.is_encrypted:
print("This document is encrypted!")
else:
print("This document is not encrypted!")
This document is not encrypted!
import pypdf
File = open("doc_is_encrypted.pdf", "rb")
reader = pypdf.PdfReader(File)
if reader.is_encrypted:
print("This document is encrypted!")
else:
print("This document is not encrypted!")
This document is encrypted!
Now assume the documents are merged:
import pypdf
File = open("doc_merged.pdf", "rb")
reader = pypdf.PdfReader(File)
if reader.is_encrypted:
print("This document is encrypted!")
else:
print("This document is not encrypted!")
This document is encrypted!
Of course it is encrypted, but I was wondering if anyone knows if it is possible to determine the pages that are actually encrypted using pypdf
?
Here you can get the files to make the problem reproducible.