I am utilizing Django 4.1.3, templated_docs, and Jsignature. I am hoping to be able to place the signature image generated by jsignature directly to the document.
I have attempted almost every combination of utilizing Draw_signature, templated_docs {% image %}, and even {{form.media}} {{form.field}} noted in Jsignature.
any insight here is helpful.
from templated_docs import fill_template
from templated_docs.http import FileResponse
from django.http import HttpResponseNotFound
from invoiceManager.models import Invoice
from jsignature.utils import draw_signature
def invoice_view(request, **kwargs):
pk = kwargs.get('pk', None)
if pk:
# try:
invoice = Invoice.objects.get(pk=pk)
information = {
'repairDate': invoice.repair_date,
'claim': invoice.claim_authorization_number,
'customerName': invoice.customer.name,
'customerAddress': invoice.customer.address,
'customerCityStateZip': f'{invoice.customer.city} {invoice.customer.state.abbreviation}, {invoice.customer.zip_code}',
'customerPhone': invoice.customer.phone_number,
'insuranceName': invoice.insurance.name,
'policyNumber': f'policy Number: {invoice.policy_number}',
'VIN': f'VIN: {invoice.vehicle_information.vin}',
'YMM': f'{invoice.vehicle_information.year} {invoice.vehicle_information.make} {invoice.vehicle_information.model}',
'customerSignature': draw_signature(invoice.signature),
'technician': invoice.technician.name,
'location': invoice.business_location.name,
'submissionDate': invoice.invoice_submission_date,
'amount':invoice.invoice_amount,
}
repairLocations = {f'RL{x}':"Repair Made" for x in invoice.location_of_repairs.all().values_list('id', flat=True).order_by().distinct()}
information.update(repairLocations)
filename = fill_template(
'docs/base_invoice.odt', information,
output_format=".pdf")
visible_filename = 'invoice{}'.format(".pdf")
return FileResponse(filename, visible_filename)
I rewrote the image tag to accept a path allowing the use of jsignature.draw_siganture(, as_file=True). Creating a temp file that can be referenced by PIL and then redrawn -- less than ideal, but allowed to maintain aspect ratio/size of the jsignature field.