0
As an alternative solution, you could try wkhtmltopdf
https://github.com/incuna/django-wkhtmltopdf. Usage is fairly simple. You should build the desired layout as a simple HTML template and give to PDFTemplateView
which will then render pdf file as response.
from django.conf.urls.defaults import url
from wkhtmltopdf.views import PDFTemplateView
urlpatterns = patterns('',
url(r'^pdf/$', PDFTemplateView.as_view(template_name='my_template.html',
filename='my_pdf.pdf'), name='pdf'),
)
2
I think you actually have two questions: 1-how to handle json data in python, and 2-how to generate a pdf out of a template (correct me if I’m wrong)
I’m gonna answer the second question here. Search the web for the first one
After json conversion, you can send the converted data to your html template and generate a pdf using pdfkit.
template = get_template("app_name/template.html")
context = Context({'data1':value1, 'data2':valu2})
html = template.render(context)
pdf = pdfkit.from_string(html, False)
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename=output.pdf'
return response
- [Answered ]-Django – user profile :UNIQUE constraint failed: main_userprofile.user_id
- [Answered ]-Django not showing updated data from database
- [Answered ]-Django Heroku DataError when populating database from script
- [Answered ]-Django css static not load
- [Answered ]-Django: what is the difference between redirect to a view function and redirect to a url (from urls.py file)
- [Answered ]-Django Apache: Target WSGI Script Cannot Be Loaded as Python Module
- [Answered ]-Why is pip installation of scipy failing in elastic beanstalk?
- [Answered ]-Environment can only contain strings- wagtail CMS, Django
Source:stackexchange.com