quarta-feira, 5 de outubro de 2011

Pyramid - convertendo html para pdf

import cStringIO as StringIO
import ho.pisa as pisa
from pyramid.renderers import render


def pdf( request ):
    
    request.response.content_type = 'application/pdf'

    request.response.headerlist.append( ( 'Content-Disposition', 'attachment; filename=test.pdf' ) )
    
    value = {}
    
    html = render( 'nameoftheproject:templates/foobar.jinja2', value, request )
    
    result = StringIO.StringIO()
    
    pisa.pisaDocument( StringIO.StringIO( html.encode( "UTF-8" ) ), result )
    
    request.response.write( result.getvalue() )

    return request.response
Agistech.com.br

Nenhum comentário:

Postar um comentário