PDF generation using easy pdf
Easy pdf is a pdf rendering django package. You can install it with the following command:
$ pip install django-easy-pdf
$ pip install "xhtml2pdf>=0.0.6" "reportlab>=2.7,<3"
Easy pdf documentation can be found hereNow in your views.py file:
import easy_pdf
from easy_pdf.views import PDFTemplateView
class MyView(PDFTemplateView):
template_name = "converter.html"
pdf_filename = "Output.pdf"
def post(self, request, args, kwargs):
objects = MyReport.objects.all()
context = { 'objects' : objects}
return easy_pdf.rendering.render_to_pdf_response(request, self.template_name, context, filename='Output.pdf', encoding=u'utf-8', **kwargs)
Now in urls.py :
from app.views import MyView
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^convert/$', MyView.as_view(), name="convert2pdf"),
)
Finally call the 'convert' url to obtain the pdf document.
No comments:
Post a Comment