2
I am developing an application with Django and need to display the result of an Assessment (test) that will have text, images and graphics. Initially I did this part using Chart.js based on this example: https://youtu.be/1OL5n06kO_w
The problem is that I also need the option to generate a pdf from this test result page while maintaining the formatting and graphics. I can generate pdf with images and text, but it loses the formatting of the text and does not display the charts of Chart.js.
I need to change how to generate the chart by abandoning Chart.js or the problem is how I am trying to generate the pdf by stepping.pisaDocument as below:
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return None
It is worth mentioning that I tried several different ways to generate the pdf. So I wonder if I should not change the way the graphics.
– user3922549
Create page with what you need with Graphic images text in the pattern you need and use https://weasyprint.org/ ... It mounts the pdf using the html css instructions
– stack.cardoso