Okay, I get that bit now, and coded it up, but when I go to render it, I use the pyramid.renderers.render object but obviously it ends up downloading a corrupted file because it's not even in PDF format.
So does reportlab have something to take that html/css and paint it to a Canvas or something? The overall idea here is that I was hoping to be able to define how I want the PDF output to look at by using CSS. if pdf: # I need to build the Response object myself from pyramid.renderers import render from pyramid.response import Response result = render('frontend:templates/student_pyp_report.pt', dict( title=title, report=report, student=student, pdf=True ), request=request) response = Response( result, content_disposition="attachment; filename={}.pdf".format("test" ), content_type = "application/pdf", charset="utf-8" ) return response else: return dict( title=title, report= report, student=student, pdf=False ) On Sunday, January 25, 2015 at 5:59:38 PM UTC+8, Wichert Akkerman wrote: > > > On 25 Jan 2015, at 07:37, Adam Morris <adam....@igbis.edu.my <javascript:>> > wrote: > > I have a view that serves up a page that whose template/css contain both > define screen and print media. Which means the view's renderer provides a > page that serves up html that is formatted for the browser (screen media) > and if the user prints it formatted for the page (the print media). The CSS > that does this is: > > <link rel="stylesheet" href="${static_url}css/reports.css" > media="screen"> > <link rel="stylesheet" href="${static_url}css/reports_pdf.css" > media="print"> > > I want to add a view that returns a FileResponse, as rendered by the print > media, so that particular location results in a download of that PDF, but I > don't want to repeat code. > > I don't want to serve a static asset, I want the PDF to be dynamically > created. > > Any ideas on how to tackle this best? > > > Here is an example: > https://github.com/wichert/checking/blob/master/src/checking/invoice.py#L306 > > The basic approach is: generate your data (in this case the PDF file), > create a response object using your data, set the right headers for it and > return it from your view. > > Wichert. > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.