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:
parent
f15da4a658
commit
14868f4264
2 changed files with 10 additions and 5 deletions
|
@ -32,9 +32,11 @@ def pdfinfo(file_path):
|
||||||
cmd_output = subprocess.check_output(['/usr/bin/pdfinfo', file_path])
|
cmd_output = subprocess.check_output(['/usr/bin/pdfinfo', file_path])
|
||||||
for line in cmd_output.splitlines():
|
for line in cmd_output.splitlines():
|
||||||
for label in labels:
|
for label in labels:
|
||||||
if label in line.decode():
|
try:
|
||||||
output[label] = _extract(line)
|
if label in line.decode():
|
||||||
|
output[label] = _extract(line)
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
pass
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -68,8 +68,11 @@ def new_job(request):
|
||||||
job_instance.print_operation = print_operation
|
job_instance.print_operation = print_operation
|
||||||
job_instance.user=request.user
|
job_instance.user=request.user
|
||||||
metadata = pdfinfo(request.FILES['form-%s-file' % count].temporary_file_path())
|
metadata = pdfinfo(request.FILES['form-%s-file' % count].temporary_file_path())
|
||||||
job_instance.pages = metadata["Pages"]
|
if "Pages" in metadata:
|
||||||
job_instance.save()
|
job_instance.pages = metadata["Pages"]
|
||||||
|
job_instance.save()
|
||||||
|
else:
|
||||||
|
job_form.erros[count] = {'file': ['Invalid PDF']}
|
||||||
except KeyError:
|
except KeyError:
|
||||||
job_form.errors[count] = {'file': ['This field is required.']}
|
job_form.errors[count] = {'file': ['This field is required.']}
|
||||||
if job_formset.total_error_count() == 0:
|
if job_formset.total_error_count() == 0:
|
||||||
|
|
Loading…
Reference in a new issue