From 747f5d19049f085deff977cb3aff7e552a9eedd7 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Wed, 30 Aug 2017 11:56:37 +0200 Subject: [PATCH] build in rasterization --- local/bin/uprint | 61 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/local/bin/uprint b/local/bin/uprint index b78ea80..c82339d 100755 --- a/local/bin/uprint +++ b/local/bin/uprint @@ -1,18 +1,61 @@ #!/bin/sh -if [ -z "$1" ]; then +help() { echo "usage: $0 [--colour] " echo - echo " -c | --colour print in colour" - echo " file file (print-ready) to print or -" + echo " -c | --colour print in colour" + echo " -r | --rasterize raster pdf before printing" + echo " file file (print-ready) to print or -" echo echo "print print-ready files with the UGent printers. Accepts only" echo ".txt, .ps, .pdf, .pcl, .cht and .prn." exit 1 -fi >&2 +} -if [ "$1" = "-c" -o "$1" = "--colour" ]; then - curl --silent --insecure -F "fileToPrint=@$2" -F "FormButtonSubmit=Print" 'https://we02pr06.ugent.be/hp/device/Print/Print' -else - curl --silent --insecure -F "localFile=@$1" 'https://we02pr04.ugent.be/hp/device/this.printservice?printThis' -fi > /dev/null +if [ -z "$1" ]; then help; fi >&2 + +printer="print_mono" +format="tiffscaled8" +raster="" +while [ -n "$2" ]; do + case "$1" in + -c|--colour) printer="print_colour" + format="tiffscaled24" + ;; + -r|--raster) raster="true" + ;; + *) help + ;; + esac + shift +done + +printfile="$1" +if test -n "$raster"; then + tiff="$(mktemp)" + printfile="$(mktemp)" + gs -sDEVICE="$format" -o "$tiff" "$1" + tiff2pdf -z -f -F -pA4 -o "$printfile" "$tiff" + rm "$tiff" +fi + +# pdf2ps -dLanguageLevel=1 input.pdf - | ps2pdf -sPAPERSIZE=a4 - output.pdf + +print_colour() { + echo curl --silent --insecure \ + -F "fileToPrint=@$1" \ + -F "FormButtonSubmit=Print" \ + 'https://we02pr06.ugent.be/hp/device/Print/Print' + zathura "$1" +} + +print_mono() { + echo curl --silent --insecure \ + -F "localFile=@$1" \ + 'https://we02pr04.ugent.be/hp/device/this.printservice?printThis' + zathura "$1" +} + +"$printer" "$printfile" + +if test -n "$raster"; then rm "$printfile"; fi