I am generating graph based reports and using Pygal library for it. I am able to get the graphs on html page but when I convert it into a pdf using wkhtml2pdf I am not able to get any graph.
I am rendering and putting the rendered charts in a list and then displaying them in a loop in my html template
def get_report_pdf(self, report, from_date=None, to_date=None):
svgs = report.get_all_charts(from_date, to_date)
html_string = loader.render_to_string('reporting/report-
template.html', {
'charts': svgs
})
html = HTML(string=html_string)
pdfkit.from_string(html_string, '/tmp/report-
{}.pdf'.format(report.id), options={'dpi': 300})
fs = FileSystemStorage('/tmp')
with fs.open('report-{}.pdf'.format(report.id)) as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment;
filename="report-{}.pdf"'.format(report.id)
pdf.close()
return response
My html template is as follows
<html>
<body>
{% for chart in charts %}
<div class="py">
{{chart|safe}}
</div>
{% endfor %}
<body>
</html>
get_all_chart() method returns a list of rendered chart objects
I am getting a blank pdf currently. I want the svg charts to be displayed on it.