[Zope] Generating and Downloading PDF.

Fernando Lujan flujan at uol.com.br
Wed Apr 27 16:57:50 EDT 2005


J Cameron Cooper wrote:

> Fernando Lujan wrote:
>
>> J Cameron Cooper wrote:
>>
>>> The method that contains your code must have at least the first 
>>> parameter 'self'::
>>>
>>>   def pdfwrite(self):
>>>     R = self.REQUEST.RESPONSE
>>>     R.setHeader('content-type', 'application/rtf')
>>>     R.setHeader('content-length', str(len(data)))
>>>     R.write(data)
>>>
>>> It's a way of getting access to context.
>>
>>
>> OK, thanks. But how can I pass the self parameter using the dtml-call 
>> tag? <dtml-call "pdfwrite(self)"> is correct? Because I'm using this 
>> and works fine.
>
>
> It's Python magic. When you call a function/method on an object, the 
> object is provided as the first parameter of the method. This is 
> implicit, I believe, in DTML calls, either expression or name. It's 
> explicit in TALES and Python::
>
>    context/pdfwrite
>    context.pdfwrite()


So, I put the code here. Please, what I'm missing? :)


def gerarTCE(self, id_tce, cnpj_escola='', matricula=''):

    from reportlab.lib.colors import Color
    from reportlab.lib.pagesizes import letter
    from reportlab.platypus import Paragraph, SimpleDocTemplate, XBox
        from reportlab.lib.styles import ParagraphStyle
        from reportlab.pdfgen import canvas
        import os
        import urllib
        from reportlab.lib.units import inch, cm
        import time
    import string

    _linha = cm / 2.25
    _fname = "tce"+id_tce+".pdf"
    _c = canvas.Canvas(_fname, pagesize=letter)
    _width, _height = letter
    _aW = _width - 2 * cm
    _aH = 750

    _c.bookmarkPage("TCE")
    _c.bookmarkPage("pagina1")
    _c.addOutlineEntry("TCE", "TCE")
    _c.addOutlineEntry("Pagina 1", "pagina1", 1)
    _c.showOutline()
    _c.setAuthor("NUBE - Núcleo Brasileiro de Estágios")
    _c.scale(1, 0.9)


    _c.setFont("Times-Bold", 16)
    _c.drawCentredString(_width / 2, 735, "TERMO ADITIVO")
    _c.setFont("Times-Roman", 9)
    _c.drawCentredString( _width / 2, 735, "(determinações legais 
estabelecidas no art. 5º e o §1º do art. 6º do Decreto 87.497/82 que 
regulamentou a Lei 6.494/77)")
      _c.drawCentredString( _width / 2, 725, "(Atualizada pela Medida 
Provisória N.º  1952-22 de 30/03/2000)")
       
    _c.showPage()
    _c.save()
   
    R = self.REQUEST.RESPONSE
    R.setHeader('content-type', 'application/pdf')
     R.Header('content-length', str(len(_fname)))
    R.write(_fname)



More information about the Zope mailing list