from cStringIO import StringIO
from pyramid.chameleon_zpt import render_template
from ho import pisa
import mimetypes
def pdf(request):
buffer = StringIO()
template = render_template('../templates/invoice.pt')
template = template.encode('utf-8')
pisa.CreatePDF(template, buffer)
type, encoding = mimetypes.guess_type('*.pdf')
response = Response(content_type=type)
response.body = buffer.getvalue()
response.headers.add('Content-Disposition',\
'attachment; filename=blah.pdf' )
return response
On 6 Apr 2012, at 08:27, León Domingo wrote:
> Hi,
> I have a solution for this using wkhtmltopdf.
>
> Firstly, render the template, then create a temporaty file, convert it into
> PDF with wkhtmltopdf, and return the PDF content of the generated file
> (temporary too) modifying the header list.
>
> ...
> s = render('myproject:templates/mytemplate.pt',
> dict(foo=1, bar=2), request=request)
>
> # "topdf" gets the template, creates the temporary file, calls "wkhtmltopdf"
> and returns the pdf content
> pdf = topdf(s.encode('utf-8'), page_size='A3', orientation='landscape')
>
> response = Response(pdf)
> response.content_type = 'application/pdf'
> response.headerlist.append(('Content-Disposition',
> 'attachment;filename=prueba.pdf'))
>
> Regards,
> León Domingo
>
> Ender - Factoría de Software
> [email protected]
> Avda. Cerro del Águila, 7. S23 - 2ª Planta
> 28703 S.S. de los Reyes (MADRID)
> Tlf. 902 01 44 01
>
>
>
>
> On 6 April 2012 09:17, Ottavio <[email protected]> wrote:
> Il giorno venerdì 6 aprile 2012 08:49:50 UTC+2, malthe ha scritto:
> You can use Chameleon to generate HTML which you'll then give to a PDF
> formatter such as the CSS3-capable PrinceXML – that's a commercial
> offering though.
>
> An alternative is Apache FOP – that's free, but input is XML, not HTML.
>
> \malthe
>
> what I'm thinking about is more ore less wrapping reportlab or some other
> library in a renderer.
>
> FOP is a java program, I don't have java on my servers...
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/q7bAbZ6ncS8J.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
Simon Oram
Lead Developer
Electrosoup
t: 07812757571
e: [email protected]
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.