Changeset 734

Show
Ignore:
Timestamp:
06/06/06 10:01:18 (3 years ago)
Author:
mfenniak
Message:

Add support for reading document information dictionary.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pypdf/trunk/pyPdf/pdf.py

    r731 r734  
    209209        self.read(stream) 
    210210        self.stream = stream 
     211 
     212    def getDocumentInfo(self): 
     213        """ 
     214        Retrieves the PDF file's document information dictionary, if it 
     215        exists.  Returns a DocumentInformation instance, or None. 
     216        Note that some PDF files use metadata streams instead of docinfo 
     217        dictionaries, and these metadata streams will not be accessed by this 
     218        function. 
     219 
     220        Stability: Added in v1.6, will exist for all v1.x releases. 
     221        """ 
     222        if not self.trailer.has_key("/Info"): 
     223            return None 
     224        obj = self.getObject(self.trailer['/Info']) 
     225        retval = DocumentInformation() 
     226        retval.update(obj) 
     227        return retval 
    211228 
    212229    def getNumPages(self): 
     
    483500class PageObject(DictionaryObject): 
    484501    def __init__(self, pdf): 
     502        DictionaryObject.__init__(self) 
    485503        self.pdf = pdf 
    486504 
     
    742760 
    743761 
     762class DocumentInformation(DictionaryObject): 
     763    def __init__(self): 
     764        DictionaryObject.__init__(self) 
     765 
     766    title = property( 
     767            lambda self: self.get("/Title", None), 
     768            None, None, 
     769            """The document's title, or None if not specified.  Added to pyPdf 
     770            in v1.6, will exist for all v1.x.""") 
     771 
     772    author = property( 
     773            lambda self: self.get("/Author", None), 
     774            None, None, 
     775            """The name of the person who created the document, or None if not 
     776            specified.  Added to pyPdf in v1.6, will exist for all v1.x.""") 
     777 
     778    subject = property( 
     779            lambda self: self.get("/Subject", None), 
     780            None, None, 
     781            """The subject of the document, or None if not specified.  Added to 
     782            pyPdf in v1.6, will exist for all v1.x.""") 
     783 
     784    creator = property( 
     785            lambda self: self.get("/Creator", None), 
     786            None, None, 
     787            """If the document was converted to PDF from another format, the 
     788            name of the application (for example, OpenOffice) that created the 
     789            original document from which it was converted, or None if not 
     790            specified.  Added to pyPdf in v1.6, will exist for all v1.x.""") 
     791 
     792    producer = property( 
     793            lambda self: self.get("/Producer", None), 
     794            None, None, 
     795            """If the document was converted to PDF from another format, the 
     796            name of the application (for example, OSX Quartz) that converted it 
     797            to PDF.  Added to pyPdf in v1.6, will exist for all v1.x.""") 
     798 
     799 
    744800def convertToInt(d, size): 
    745801    if size <= 4: