demos/rlzope/rlzope.py
branchpy33
changeset 3721 0c93dd8ff567
parent 3256 f31a47336a0f
child 3794 398ea04239b5
equal deleted inserted replaced
3720:7a059dde5bf5 3721:0c93dd8ff567
    10 #
    10 #
    11 # Author : Jerome Alet - alet@librelogiciel.com
    11 # Author : Jerome Alet - alet@librelogiciel.com
    12 #
    12 #
    13 #
    13 #
    14 
    14 
    15 import string, cStringIO
    15 import string, io
    16 try :
    16 try :
    17     from Shared.reportlab.platypus.paragraph import Paragraph
    17     from Shared.reportlab.platypus.paragraph import Paragraph
    18     from Shared.reportlab.platypus.doctemplate import *
    18     from Shared.reportlab.platypus.doctemplate import *
    19     from Shared.reportlab.lib.units import inch
    19     from Shared.reportlab.lib.units import inch
    20     from Shared.reportlab.lib import styles
    20     from Shared.reportlab.lib import styles
    53             except AttributeError :
    53             except AttributeError :
    54                 # not found !
    54                 # not found !
    55                 return None
    55                 return None
    56 
    56 
    57             # Convert it to PIL
    57             # Convert it to PIL
    58             image = ImageReader(cStringIO.StringIO(str(logo.data)))
    58             image = ImageReader(io.StringIO(str(logo.data)))
    59             (width, height) = image.getSize()
    59             (width, height) = image.getSize()
    60 
    60 
    61             # scale it to be 0.75 inch high
    61             # scale it to be 0.75 inch high
    62             multi = ((height + 0.0) / (0.75 * inch))
    62             multi = ((height + 0.0) / (0.75 * inch))
    63             width = int(width / multi)
    63             width = int(width / multi)
    82         self.built = 0
    82         self.built = 0
    83         self.objects = []
    83         self.objects = []
    84 
    84 
    85         # we will build an in-memory document
    85         # we will build an in-memory document
    86         # instead of creating an on-disk file.
    86         # instead of creating an on-disk file.
    87         self.report = cStringIO.StringIO()
    87         self.report = io.StringIO()
    88 
    88 
    89         # initialise a PDF document using ReportLab's platypus
    89         # initialise a PDF document using ReportLab's platypus
    90         self.document = BaseDocTemplate(self.report)
    90         self.document = BaseDocTemplate(self.report)
    91 
    91 
    92         # add our page template
    92         # add our page template
   156             pass
   156             pass
   157         self.REQUEST.RESPONSE.setHeader('Content-Type', 'application/pdf')
   157         self.REQUEST.RESPONSE.setHeader('Content-Type', 'application/pdf')
   158         self.REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s' % filename)
   158         self.REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s' % filename)
   159     except:
   159     except:
   160         import traceback, sys, cgi
   160         import traceback, sys, cgi
   161         content = sys.stdout = sys.stderr = cStringIO.StringIO()
   161         content = sys.stdout = sys.stderr = io.StringIO()
   162         self.REQUEST.RESPONSE.setHeader('Content-Type', 'text/html')
   162         self.REQUEST.RESPONSE.setHeader('Content-Type', 'text/html')
   163         traceback.print_exc()
   163         traceback.print_exc()
   164         sys.stdout = sys.__stdout__
   164         sys.stdout = sys.__stdout__
   165         sys.stderr = sys.__stderr__
   165         sys.stderr = sys.__stderr__
   166         content = '<html><head></head><body><pre>%s</pre></body></html>' % cgi.escape(content.getvalue())
   166         content = '<html><head></head><body><pre>%s</pre></body></html>' % cgi.escape(content.getvalue())