Advertisement
rfmonk

pdfMetaWorks.py

Nov 30th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/env python
  2.  
  3. """ this was fixed from the previous version because pdf_meta.py had the if __name__ == '__main__': code inside the main function. That always needs to be in the document not in the function. Thanks Javantea =]
  4. There was also a typo printmeta(filename): should be printMeta(filename): If this still throws an exception
  5. check the indentation on the last main().
  6. usage:
  7.     python pdf_meta.py -F <filename> #where <filename> is your pdf, dont use <>"""
  8.  
  9. import pyPdf
  10. import optparse
  11. from pyPdf import PdfFileReader
  12. def printMeta(filename):
  13.     pdfFile = PdfFileReader(file(filename, 'rb'))
  14.     docInfo = pdfFile.getDocumentInfo()
  15.     print '[*] PDF MetaData For: ' + str(filename)
  16.     for metaItem in docInfo:
  17.         print '[+] ' + metaItem + ':' + docInfo[metaItem]
  18. def main():
  19.     parser = optparse.OptionParser('usage %prog "+\
  20.         "-F <PDF file name>')
  21.     parser.add_option('-F', dest='fileName', type='string',\
  22.         help='specify PDF file name')
  23.     (options, args) = parser.parse_args()
  24.     fileName = options.fileName
  25.     if fileName == None:
  26.         print parser.usage
  27.         exit(0)
  28.     else:
  29.         printMeta(fileName)
  30. if __name__ == '__main__':
  31.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement