import fitz # this is PyMuPDF# doc1 = "IOT.pdf"withopen(r"C:\Users\84977\Desktop\test2.pdf",'r+')as doc1:
doc = fitz.Document(doc1)# the document should be password protectedprint(doc.isEncrypted)
使用PyPDF3
pip install PyPDF3
import PyPDF3
pdffile=open('IOT.pdf','rb')
pdfreader= PyPDF3.PdfFileReader(pdffile)try:# print decryption outcome as 1 if successful and 0 otherwise
pdfreader.decrypt('password')except NotImplementedError as errMsg:print(pdfreader,'can not be decrypted on error message', errMsg)
pdffile.close()