Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try the solution from <a href="http://www.reportlab.org/" rel="noreferrer">Reportlab</a>.</p> <p>Download it and install it as usual with python setup.py install</p> <p>You will also need to install the following modules: xhtml2pdf, html5lib, pypdf with easy_install.</p> <p>Here is an usage example:</p> <p><strong>First define this function:</strong></p> <pre><code>import cStringIO as StringIO from xhtml2pdf import pisa from django.template.loader import get_template from django.template import Context from django.http import HttpResponse from cgi import escape 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(), content_type='application/pdf') return HttpResponse('We had some errors&lt;pre&gt;%s&lt;/pre&gt;' % escape(html)) </code></pre> <p><strong>Then you can use it like this:</strong></p> <pre><code>def myview(request): #Retrieve data or whatever you need return render_to_pdf( 'mytemplate.html', { 'pagesize':'A4', 'mylist': results, } ) </code></pre> <p><strong>The template:</strong></p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;My Title&lt;/title&gt; &lt;style type="text/css"&gt; @page { size: {{ pagesize }}; margin: 1cm; @frame footer { -pdf-frame-content: footerContent; bottom: 0cm; margin-left: 9cm; margin-right: 9cm; height: 1cm; } } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; {% for item in mylist %} RENDER MY CONTENT {% endfor %} &lt;/div&gt; &lt;div id="footerContent"&gt; {%block page_foot%} Page &lt;pdf:pagenumber&gt; {%endblock%} &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Hope it helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload