'extract signature from SignatureField in Django

here i am using python3 and Django 3.0 Here am i saving the signature into my database and now i need to display this signature in my pdf file

But i am not able to display it in the pdf file

here is my views.py

def jobspecific_view_1(request, pk):
    form = CustomerSignatureForm(request.POST or None)
    if form.is_valid():
        customer_signature_1 = 
              form.cleaned_data.get('customer_signature_1')
        if customer_signature_1!=None:
            job = AddJob.objects.get(id=pk)
            job.customer_signature_1 = customer_signature_1
            job.save()
       ......
       ......

here is my views.py for generating the pdf

def render_to_pdf(template_src, context_dict, pdf_title):
    template = get_template(template_src)
    context =  Context(context_dict)
    html  = template.render(context_dict)
    result = BytesIO()
    pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), result,
                        encoding='UTF-8')

    if not pdf.err:
        response =  HttpResponse(result.getvalue(), content_type='application/pdf')
        response['Content-Disposition'] = "attachment; filename={0}".format(
                                            unidecode(
                                                pdf_title.replace(
                                                    ',', '').replace(
                                                        ';', '').replace(' ', '_')))
    logger.debug('Content-Disposition: {0}'.format(response['Content-Disposition']))
    return response

    logger.error(pdf.err)
    return HttpResponse('We had some errors<pre>%s</pre>' % cgi.escape(html))
  
def generate_pdf_view(request, pk):
    client = request.user.client
    job_id = AddJob.objects.filter(id=pk)
    viewed_job = get_object_or_404(AddJob, id=pk, created_by__client=client)
    job_data={}
    for val in job_id:
        job_data['job_id'] = pk
        job_data['title'] = val.title
        job_data['job_number'] = val.job_number
        job_data['customer_signature_1'] = val.customer_signature_1
        ......
        ......
    pdf_title = u'{0}_{1}_{2}.pdf'.format(
                    job_data['title'], job_date.strftime('%d_%m_%Y'),
                    job_data['job_type'])
    return render_to_pdf('jobs/jobpdf.html',
                     {
                        'pagesize':'A4', 'job_data': job_data,
                        'viewed_job': viewed_job,
                        'request': request,
                     }, pdf_title)

Here is my forms.py

class CustomerSignForm(forms.ModelForm):
    customer_signature_1 = SignatureField(required=False,label="Customer Signature")
    class Meta:
        model = AddJob
        fields = ['customer_signature_1']

Here is my jobspdf.html

<img src="data:image/png;base64,{{job_data.custmer_signature_1}}"/>

Please help me so that i can display the signature in my pdf view at present it not displaying anything in my pdf



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source