Checking if a PDF file is password-protected
I know of several tools/libraries that can do this but I want to know if this is possible with just opening up the file开发者_高级运维 as a text file and looking for a keyword.
You could do this in about 4 lines of Python with the slate
package:
>>> import slate
>>> with open('file.pdf, 'rb') as f:
... doc = slate.PDF(f, 'password')
>>> 'keyword' in doc.text()
True
精彩评论