**QPainter::begin(): Returned false============================] 100%
Error: Unable to write to destination Exit with code 1, due to unknown error.**
def view_entry_pdf(request,id):
standard_fields = ['user_username','user_email', 'form_id', 'entry_id', 'date_dmy','user_full_name']
try:
entry = Entries.objects.get(pk=id)
cert = Certificate.objects.filter(form_id=entry.form.id, is_active=1).first()
get_cert = request.GET.get('cert_id','')
if get_cert:
cert = Certificate.objects.get(id=get_cert)
if not cert:
messages.warning(request, 'PDF template not found.')
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
valid_rules = validate_rules(entry,cert, cert.rules.all())
if valid_rules:
pass
else:
messages.warning(request, 'Certificate rules not matched.')
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
entry.is_read = True
entry.save()
file_name = 'entry-certificate.pdf'
if cert.file_name:
file_name = cert.file_name
res = re.findall(r'(\{\{[^}]+}\})', file_name)
placeholders = {}
standard_placeholders = {}
#standard_fields
for sf in standard_fields:
sfv = ''
if sf == 'user_username':
sfv = entry.user.username
elif sf == 'user_email':
sfv = entry.user.email
elif sf == 'form_id':
sfv = str(entry.form.id)
elif sf == 'entry_id':
sfv = str(entry.id)
elif sf == 'date_dmy':
today = datetime.now().date()
sfv = today.strftime("%d-%m-%Y")
elif sf == 'user_full_name':
sfv = f"{entry.user.first_name} {entry.user.last_name}"
standard_placeholders['{{'+sf+'}}'] = sfv
standard_placeholders = account_placeholders(request, standard_placeholders)
if res:
fields_all = entry.form.fields.all().order_by('sort_order')
for f in fields_all:
key = '{{'+f.label_name.replace(" ", "_").lower()+'}}'
placeholders[key] = f.id
for p in res:
f_id = placeholders.get(p)
if p and f_id:
en_data = entry.columns.filter(field_id=f_id)
val = ''
if en_data.count() and en_data[0].value:
val = en_data[0].value
file_name = file_name.replace(p, val)
elif standard_placeholders.get(p):
file_name = file_name.replace(p, standard_placeholders[p])
cert_path = '{}/form/certificates/{}'.format(settings.MEDIA_ROOT,file_name)
#cert_path = 'media/form/certificates/{file_name}'
url = '{}://{}/admin/forms/entry-pdf/{}?system_run=1&cert={}'.format(request.scheme, request.get_host(), entry.id, cert.id)
print("reached here------------------------------")
options = {
'dpi': 365,
'page-size':cert.page_type,
'orientation':cert.orientation
}
pdfkit.from_url(url,cert_path,options=options)
#set pdf permissions
setPdfPermissions(cert, cert_path)
return FileResponse(open(cert_path, 'rb'), content_type='application/pdf')
except FileNotFoundError:
raise Http404()
I am converting html to pdf. This code worked fine before. I dont know what kind of problem is arrising now. I am not aware of this tool htmltopdf. If i am doing anything wrong please help me