diff --git a/cups-pdf-postprocess.py b/cups-pdf-postprocess.py index 0ad636e7f17b1315a716f9d486ee0be49653158c..130bba5b96339f957ccb84dbaa48e5fd1724547a 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 0000000000000000000000000000000000000000..449682cde9e4d628ab5056faf0492b0b7393bde9 --- /dev/null +++ b/pdfcrop_wrapper.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cd /tmp +exec pdfcrop "$@" +