diff --git a/src/calibre/ebooks/pdf/pdftrim.py b/src/calibre/ebooks/pdf/pdftrim.py index b194d93b9d..2054f22558 100644 --- a/src/calibre/ebooks/pdf/pdftrim.py +++ b/src/calibre/ebooks/pdf/pdftrim.py @@ -29,7 +29,7 @@ def config(defaults=None): c.add_opt('top_right_y', [ '-w', '--righty'], default=default_crop, help=_('Number of pixels to crop from the right most y (default is %d)')%default_crop ) c.add_opt('bounding', ['-b', '--bounding'], - help=_('A file generated by ghostscript which allows each page to be individually cropped')) + help=_('A file generated by ghostscript which allows each page to be individually cropped [gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox > bounding] ')) return c @@ -38,14 +38,24 @@ def option_parser(): return c.option_parser(usage=_('''\ %prog [options] file.pdf - Crop a pdf. + Crops a pdf. ''')) def main(args=sys.argv): parser = option_parser() opts, args = parser.parse_args(args) - source = os.path.abspath(args[1]) - input_pdf = PdfFileReader(file(source, "rb")) + try: + source = os.path.abspath(args[1]) + input_pdf = PdfFileReader(file(source, "rb")) + except: + print "Unable to read input" + return 2 + info = input_pdf.getDocumentInfo() + title = 'Unknown' + author = 'Unknown' + if info.title: + title = info.title + author = info.author if opts.bounding != None: try: bounding = open( opts.bounding , 'r' ) @@ -53,7 +63,7 @@ def main(args=sys.argv): except: print 'Error opening %s' % opts.bounding return 1 - output_pdf = PdfFileWriter() + output_pdf = PdfFileWriter(title=title,author=author) for page_number in range (0, input_pdf.getNumPages() ): page = input_pdf.getPage(page_number) if opts.bounding != None: diff --git a/src/pyPdf/pdf.py b/src/pyPdf/pdf.py index 3cf7a60f0e..362879a39a 100644 --- a/src/pyPdf/pdf.py +++ b/src/pyPdf/pdf.py @@ -55,7 +55,7 @@ from utils import readNonWhitespace, readUntilWhitespace, ConvertFunctionsToVirt # This class supports writing PDF files out, given pages produced by another # class (typically {@link #PdfFileReader PdfFileReader}). class PdfFileWriter(object): - def __init__(self): + def __init__(self,title=u"Unknown",author=u"Unknown"): self._header = "%PDF-1.3" self._objects = [] # array of indirect objects @@ -71,7 +71,9 @@ class PdfFileWriter(object): # info object info = DictionaryObject() info.update({ - NameObject("/Producer"): createStringObject(u"Python PDF Library - http://pybrary.net/pyPdf/") + NameObject("/Producer"): createStringObject(u"Python PDF Library - http://pybrary.net/pyPdf/"), + NameObject("/Author"): createStringObject(author), + NameObject("/Title"): createStringObject(title), }) self._info = self._addObject(info)