RML2PDF with Django

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template import Template, Context
from rlextra.rml2pdf import rml2pdf
import cStringIO

def getPDF(request):
    """Returns PDF as a binary stream."""
    if 'q' in request.GET:
        name = request.GET['q']
        t = Template(open('hello.rml').read())
        c = Context({"name": name})
        rml = t.render(c)
        buf = cStringIO.StringIO()
        #create the pdf
        rml2pdf.go(rml, outputFileName=buf)
        buf.reset()
        pdfData = buf.read()
        #send the response
        response = HttpResponse(mimetype='application/pdf')
        response.write(pdfData)
        response['Content-Disposition'] = 'attachment; filename=output.pdf'
        return response

More like this

  1. Something like list_detail generic view but returns PDF document instead by aurelije 4 years, 8 months ago
  2. Create PDF files using rml and django templates by mporrato 5 years, 11 months ago
  3. PDF generation directly using HTML by perenzo 5 years, 2 months ago
  4. pyText2Pdf - Python script to convert plain text into PDF file. Modified to work with streams. by vsergeyev 3 years, 6 months ago
  5. Use django-admin.py instead of manage.py by whiteinge 4 years, 11 months ago

Comments

(Forgotten your password?)