8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-24 20:33:11 +00:00

[Printer] Handles pdf with fancy encoding in metadata

This commit is contained in:
Maxime Bombar 2018-10-30 22:21:11 +01:00 committed by root
parent f15da4a658
commit 14868f4264
2 changed files with 10 additions and 5 deletions

View file

@ -32,9 +32,11 @@ def pdfinfo(file_path):
cmd_output = subprocess.check_output(['/usr/bin/pdfinfo', file_path])
for line in cmd_output.splitlines():
for label in labels:
if label in line.decode():
output[label] = _extract(line)
try:
if label in line.decode():
output[label] = _extract(line)
except UnicodeDecodeError:
pass
return output

View file

@ -68,8 +68,11 @@ def new_job(request):
job_instance.print_operation = print_operation
job_instance.user=request.user
metadata = pdfinfo(request.FILES['form-%s-file' % count].temporary_file_path())
job_instance.pages = metadata["Pages"]
job_instance.save()
if "Pages" in metadata:
job_instance.pages = metadata["Pages"]
job_instance.save()
else:
job_form.erros[count] = {'file': ['Invalid PDF']}
except KeyError:
job_form.errors[count] = {'file': ['This field is required.']}
if job_formset.total_error_count() == 0: