문제

I've currently run into the need to find which pdfs within a directory are "Secured Documents". All of the pdfs should be unsecured, and convertible via xpdf, however, this is not the case. How could I scan through all the pdfs in a directory to find out whether or not they are secured?

도움이 되었습니까?

해결책

pyPdf supports decrypting PDFs. Its PdfFileReader class has an isEncrypted attribute.

import pyPdf
if pyPdf.PdfFileReader(open("file_name.pdf", 'rb')).isEncrypted:
    print "Rut ro, it's encrypted."
    # skip file? Write to a log?
else:
    print "We're clear."
    # Do stuff with the file.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top