true pdfreader getpage( traceback (most recent call last)file ""line in pdfreader getpage(--snip-file " :\python \lib\site-packages\pypdf \pdf py"line in getobject raise utils pdfreaderror("file has not been decrypted"pypdf utils pdfreaderrorfile has not been decrypted pdfreader pypdf pdffilereader(open('encrypted pdf''rb')pdfreader decrypt('rosebud' pageobj pdfreader getpage( all pdffilereader objects have an isencrypted attribute that is true if the pdf is encrypted and false if it isn' any attempt to call function that reads the file before it has been decrypted with the correct password will result in an error note due to bug in pypdf version calling getpage(on an encrypted pdf before calling decrypt(on it causes future getpage(calls to fail with the following errorindexerrorlist index out of range this is why our example reopened the file with new pdffilereader object to read an encrypted pdfcall the decrypt(function and pass the password as string after you call decrypt(with the correct passwordyou'll see that calling getpage(no longer causes an error if given the wrong passwordthe decrypt(function will return and getpage(will continue to fail note that the decrypt(method decrypts only the pdffilereader objectnot the actual pdf file after your program terminatesthe file on your hard drive remains encrypted your program will have to call decrypt(again the next time it is run creating pdfs pypdf ' counterpart to pdffilereader is pdffilewriterwhich can create new pdf files but pypdf cannot write arbitrary text to pdf like python can do with plaintext files insteadpypdf ' pdf-writing capabilities are limited to copying pages from other pdfsrotating pagesoverlaying pagesand encrypting files pypdf doesn' allow you to directly edit pdf insteadyou have to create new pdf and then copy content over from an existing document the examples in this section will follow this general approach open one or more existing pdfs (the source pdfsinto pdffilereader objects create new pdffilewriter object