The pisa pypi entry suggests that you switch to xml2pdf:
https://pypi.python.org/pypi/xhtml2pdf


On Wed, Feb 20, 2013 at 2:05 PM, Satinderpal Singh <
satinder.goray...@gmail.com> wrote:

> I am trying to produce pdf from html using the following code, but
> unable to do so, it gives an error that, global name 'results' is not
> defined. Please tell me how to use this view.
>
> def render_to_pdf(template_src, context_dict):
>     template = get_template(template_src)
>     context = Context(context_dict)
>     html  = template.render(context)
>     result = StringIO.StringIO()
>
>     pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")),
> result)
>     if not pdf.err:
>         return HttpResponse(result.getvalue(), mimetype='application/pdf')
>     return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))
>
> def myview(request):
>     #Retrieve data or whatever you need
>     return render_to_pdf(
>             'report/pdf.html',
>             {
>                 'pagesize':'A4',
>                 'mylist': results,
>             }
>         )
>
> in the report/pdf.html there is:
>
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd";>
> <html>
>     <head>
>         <title>My Title</title>
>         <style type="text/css">
>             @page {
>                 size: {{ pagesize }};
>                 margin: 1cm;
>                 @frame footer {
>                     -pdf-frame-content: footerContent;
>                     bottom: 0cm;
>                     margin-left: 9cm;
>                     margin-right: 9cm;
>                     height: 1cm;
>                 }
>             }
>         </style>
>     </head>
> {% block report %}
>     <body>
>         <div>
>             {% for item in mylist %}
>                 {{item}}
>             {% endfor %}
>         </div>
>         <div id="footerContent">
>             {%block page_foot%}
>                 Page <pdf:pagenumber>
>                  <pdf:barcode>
>             {%endblock%}
>         </div>
>     </body>
> </html>
>
>
> --
> Satinderpal Singh
> http://satindergoraya.blogspot.in/
> http://satindergoraya91.blogspot.in/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to