added PDF Creator to document info
authorandy
Wed, 29 Sep 2010 19:37:05 +0000
changeset 3456 3143bbebbefe
parent 3455 8621e62c469d
child 3457 47d2296b4a9f
added PDF Creator to document info
src/reportlab/pdfbase/pdfdoc.py
src/reportlab/pdfgen/canvas.py
src/reportlab/platypus/doctemplate.py
tests/test_pdfgen_general.py
--- a/src/reportlab/pdfbase/pdfdoc.py	Wed Sep 29 14:20:28 2010 +0000
+++ b/src/reportlab/pdfbase/pdfdoc.py	Wed Sep 29 19:37:05 2010 +0000
@@ -350,6 +350,15 @@
         else:
             self.info.subject = subject
 
+    def setCreator(self, creator):
+        "embeds in PDF file"
+
+        #allow resetting to clear it
+        if creator is None:
+            self.info.creator = '(unspecified)'
+        else:
+            self.info.creator = creator
+
     def setKeywords(self, keywords):
         "embeds a string containing keywords in PDF file"
 
@@ -1546,7 +1555,8 @@
     File | Document Info in Acrobat Reader.  If this is wrong, you get
     Postscript errors while printing, even though it does not print."""
     __PDFObject__ = True
-    producer = "ReportLab http://www.reportlab.com"
+    producer = "ReportLab PDF Library - www.reportlab.com"
+    creator = "ReportLab PDF Library - www.reportlab.com"
     title = "untitled"
     author = "anonymous"
     subject = "unspecified"
@@ -1567,6 +1577,7 @@
         D["Author"] = PDFString(self.author)
         D["CreationDate"] = PDFDate(invariant=self.invariant,dateFormatter=self._dateFormatter)
         D["Producer"] = PDFString(self.producer)
+        D["Creator"] = PDFString(self.creator)
         D["Subject"] = PDFString(self.subject)
         D["Keywords"] = PDFString(self.keywords)
 
--- a/src/reportlab/pdfgen/canvas.py	Wed Sep 29 14:20:28 2010 +0000
+++ b/src/reportlab/pdfgen/canvas.py	Wed Sep 29 19:37:05 2010 +0000
@@ -440,6 +440,12 @@
            in the document itself."""
         self._doc.setSubject(subject)
 
+    def setCreator(self, creator):
+        """write a creator into the PDF file that won't automatically display
+           in the document itself. This should be used to name the original app
+           which is passing data into ReportLab, if you wish to name it."""
+        self._doc.setCreator(creator)
+
     def setKeywords(self, keywords):
         """write a list of keywords into the PDF file which shows in document properties.
         Either submit a single string or a list/tuple"""
--- a/src/reportlab/platypus/doctemplate.py	Wed Sep 29 14:20:28 2010 +0000
+++ b/src/reportlab/platypus/doctemplate.py	Wed Sep 29 19:37:05 2010 +0000
@@ -433,6 +433,7 @@
                     'title':None,
                     'author':None,
                     'subject':None,
+                    'creator':None,
                     'keywords':[],
                     'invariant':None,
                     'pageCompression':None,
@@ -828,6 +829,7 @@
         self.canv.setAuthor(self.author)
         self.canv.setTitle(self.title)
         self.canv.setSubject(self.subject)
+        self.canv.setCreator(self.creator)
         self.canv.setKeywords(self.keywords)
 
         if self._onPage:
--- a/tests/test_pdfgen_general.py	Wed Sep 29 14:20:28 2010 +0000
+++ b/tests/test_pdfgen_general.py	Wed Sep 29 19:37:05 2010 +0000
@@ -872,6 +872,8 @@
     c = makeDocument(filename)
     c.setAuthor(u'R\xfcp\xe9rt B\xe8\xe4r')
     c.setTitle('R\xc3\xbcp\xc3\xa9rt B\xc3\xa8\xc3\xa4r\'s Book')
+    c.setCreator(u'Some Creator')
+    c.setSubject(u'Some Subject')
     c.save()
     c = makeDocument(filename)
     import os