From 5aa0dd867efaabd593e0fda0198d066e0e4f2e9d Mon Sep 17 00:00:00 2001 From: Maxime Bombar Date: Mon, 15 Oct 2018 03:14:37 +0200 Subject: [PATCH] [Printer] Function to create a booklet from a pdf --- apt_requirements.txt | 1 + printer/utils.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apt_requirements.txt b/apt_requirements.txt index 2a5672ee..c33fe7fb 100644 --- a/apt_requirements.txt +++ b/apt_requirements.txt @@ -18,3 +18,4 @@ fonts-font-awesome graphviz git poppler-utils +texlive-extra-utils diff --git a/printer/utils.py b/printer/utils.py index fffec47d..91b7e669 100644 --- a/printer/utils.py +++ b/printer/utils.py @@ -1,5 +1,5 @@ import subprocess - +import os def user_printing_path(instance, filename): """ @@ -35,3 +35,20 @@ def pdfinfo(file_path): output[label] = _extract(line) return output + + +def pdfbook(file_path): + """ + Creates a booklet from a pdf + requires texlive-extra-utils + """ + _dir = os.path.dirname(file_path) + _fname = os.path.basename(file_path) + newfile = os.path.join(_dir, "pdfbook_%s" % (_fname,)) + check_output( + ['/usr/bin/pdfbook', + '--short-edge', + file_path, + '-o', newfile, + ]) + return newfile