From faf7eb70853f1bbccd75e49f595f9acb8e3fa7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Hu=C5=A1ek?= <husek@iuuk.mff.cuni.cz> Date: Tue, 10 Oct 2017 21:13:43 +0200 Subject: [PATCH] add Crop option --- cups-pdf-postprocess.py | 39 +++++++++++++++++++++++++++++++++++++++ pdfcrop_wrapper.sh | 5 +++++ 2 files changed, 44 insertions(+) create mode 100755 pdfcrop_wrapper.sh diff --git a/cups-pdf-postprocess.py b/cups-pdf-postprocess.py index 0ad636e..130bba5 100755 --- a/cups-pdf-postprocess.py +++ b/cups-pdf-postprocess.py @@ -80,6 +80,38 @@ class CPP(QWidget): o.setWordWrap(True) vbox.addWidget(o) + def margin_spinbox(name, layout): + hbox = QHBoxLayout() + hbox.addWidget(QLabel(name)) + s = QSpinBox(self) + s.setMinimum(0) + s.setMaximum(100) + s.setSingleStep(1) + s.setValue(20) + s.setEnabled(False) + hbox.addWidget(s) + layout.addLayout(hbox) + return s + + hbox = QHBoxLayout() + self._crop = QCheckBox('Crop', self) + hbox.addWidget(self._crop) + _vbox = QVBoxLayout() + _vbox.addWidget(QLabel("Margins [mm]")) + self._crop_margin = ( + margin_spinbox("Left", _vbox), + margin_spinbox("Top", _vbox), + margin_spinbox("Right", _vbox), + margin_spinbox("Bottom", _vbox), + ) + hbox.addLayout(_vbox) + vbox.addLayout(hbox) + + def _crop_changed(checked): + for m in self._crop_margin: + m.setEnabled(checked) + self._crop.clicked[bool].connect(_crop_changed) + hbox = QHBoxLayout() self._compact = QCheckBox('Compact', self) self._compact_copies = QSpinBox(self) @@ -167,6 +199,13 @@ class CPP(QWidget): log.append(msg) self._logger.setPlainText("".join(log)) + MM_TO_BP = 2.83465 + + if self._crop.isChecked(): + margin = " ".join([ "%d" % (MM_TO_BP * m.value()) for m in self._crop_margin ]) + pipeline.append([ "%s/pdfcrop_wrapper.sh" % DIR, + "--margin", margin, "-", "/dev/stdout" ]) + if self._pdfbook.isChecked(): pipeline.append([ "pdfbook", "/dev/stdin", "-o", "/dev/stdout" ]) diff --git a/pdfcrop_wrapper.sh b/pdfcrop_wrapper.sh new file mode 100755 index 0000000..449682c --- /dev/null +++ b/pdfcrop_wrapper.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cd /tmp +exec pdfcrop "$@" + -- GitLab