View difference between Paste ID: RRSwBhA6 and whFWXzYh
SHOW: | | - or go back to the newest paste.
1
#! /usr/bin/env python
2
3-
""" attribution to book violent python. this is supposed to print meta to stdout, it doesn't.
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-
it doesn't throw exception, but doesn't print anything. still working on it."""
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-
def printmeta(filename):
9+
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()