Commit f38218f1 authored by Radek Hušek's avatar Radek Hušek
Browse files

add print_compact

parent e15ec051
...@@ -12,6 +12,7 @@ from PyQt5.QtCore import * ...@@ -12,6 +12,7 @@ from PyQt5.QtCore import *
import sys import sys
import subprocess as sp import subprocess as sp
import ast import ast
import os
def exec_pipeline(pipeline, inp, out = None, err_callback = None): def exec_pipeline(pipeline, inp, out = None, err_callback = None):
def make_proc(cmd): def make_proc(cmd):
...@@ -79,6 +80,32 @@ class CPP(QWidget): ...@@ -79,6 +80,32 @@ class CPP(QWidget):
o.setWordWrap(True) o.setWordWrap(True)
vbox.addWidget(o) vbox.addWidget(o)
hbox = QHBoxLayout()
self._compact = QCheckBox('Compact', self)
self._compact_copies = QSpinBox(self)
self._compact_copies.setMinimum(1)
self._compact_copies.setMaximum(1000)
self._compact_copies.setSingleStep(1)
self._compact_copies.setValue(1)
self._compact_copies.setEnabled(False)
def _compact_changed(enabled):
self._pdfbook.setEnabled(not enabled)
self._compact_copies.setEnabled(enabled)
if enabled:
self._duplex.setCurrentIndex(1)
self._pdfbook.setChecked(False)
_pdfbook_changed(False)
else:
self._compact_copies.setValue(1)
self._duplex.setEnabled(not enabled)
self._compact.clicked[bool].connect(_compact_changed)
hbox.addWidget(self._compact)
hbox.addWidget(self._compact_copies)
vbox.addLayout(hbox)
hbox = QHBoxLayout() hbox = QHBoxLayout()
hbox.addWidget(QLabel("Duplex:")) hbox.addWidget(QLabel("Duplex:"))
self._duplex = QComboBox(self) self._duplex = QComboBox(self)
...@@ -143,6 +170,10 @@ class CPP(QWidget): ...@@ -143,6 +170,10 @@ class CPP(QWidget):
if self._pdfbook.isChecked(): if self._pdfbook.isChecked():
pipeline.append([ "pdfbook", "/dev/stdin", "-o", "/dev/stdout" ]) pipeline.append([ "pdfbook", "/dev/stdin", "-o", "/dev/stdout" ])
if self._compact.isChecked():
pipeline.append([ "%s/%s" % (os.path.dirname(os.path.realpath(sys.argv[0])), "print_compact.sh"),
"%i" % self._compact_copies.value() ])
if self._printer.currentData() is SAVE_AS_FILE: if self._printer.currentData() is SAVE_AS_FILE:
f = QFileDialog.getSaveFileName(self, 'Save as ...') f = QFileDialog.getSaveFileName(self, 'Save as ...')
if not f[0]: if not f[0]:
......
#!/bin/bash
COPIES="${1:-1}"
PDF="`xxd -p`"
PAGES=`xxd -p -r <<<"$PDF" | pdfinfo - | sed -nre 's/Pages:\s*(.*)/\1/p'`
if (( PAGES <= 2)); then
: $(( COPIES = (COPIES + 1) / 2 ))
fi
xxd -p -r <<<"$PDF" |
case $PAGES in
1) pdfjam --nup 2x1 --landscape --doublepagestwistodd\* true -o /dev/stdout /dev/stdin 1,'{}';;
2) pdfjam --nup 2x1 --landscape --doublepagestwistodd\* true -o /dev/stdout /dev/stdin 1,2;;
*) pdfbook -o /dev/stdout /dev/stdin;;
esac | pdfjoin -o /dev/stdout /dev/stdin `python -c "print(','.join(['-']*$COPIES))"`
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment