3

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.

Quinten
  • 35,235
  • 5
  • 20
  • 53
  • 1
    A PDF file is either encrypted as a whole or not at all. (Ok, this is an oversimplification but mostly it's true.) In particular, all pages in your merged file are encrypted. Apparently your merging process applied the passwords of the source PDF to the whole merged PDF. – mkl Aug 22 '23 at 08:41
  • @mkl, Thank you for your comment! So it is never possible to determine which pages are encrypted? – Quinten Aug 22 '23 at 08:49
  • All pages are either encrypted or not, as @mkl already indicated. Your question is simply wrong. – Joris Schellekens Aug 22 '23 at 11:23
  • *"So it is never possible to determine which pages are encrypted?"* - Of course it is, all of them are! – mkl Aug 22 '23 at 12:25

0 Answers0