0

I have this PDFview class now i want to use it in any form template so i can see preview of that form data before sending data.

class PDFView(View):

def get(self, request, **kwargs):
    template = get_template("pim/pdfview.html")
    ctx = {}
    ctx["test"] = Employee.objects.all()

    context = Context(ctx)
    html  = template.render(context)
    result = StringIO.StringIO()
    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
    if not pdf.err:
        response = http.HttpResponse(result.getvalue(), mimetype='application/pdf')
        response['Content-Disposition'] = 'attachment; filename="leavereport.pdf"'
        return response
    return http.HttpResponse('We had some errors<pre>%s</pre>' % cgi.escape(html)) 
  • Not an exact answer, but this might help. http://stackoverflow.com/questions/6907388/updating-context-data-in-formview-form-valid-method – Jacinda May 26 '13 at 08:19
  • I'm not sure I understand what you're trying to do. Do you want to pass the PDF file to another view, or did you want to pass the rendered template? – Jack Shedd May 26 '13 at 08:50
  • My target is generate pdf of a form instance before saving it – Robert Garcia May 26 '13 at 09:01

0 Answers0