From ac7cea8dba852fa9ff191cbb877793e7e7270ddb Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Wed, 27 Jan 2010 09:52:49 +0100 Subject: [PATCH] MT2268 Printing html notices on pdf printers This adds a shell script which is able to turn html files into pdf and print them on a printer It takes a directory where pdf files is laid, a css filename, a host for printer and a Printername printoverdues : generates PDF files from html files in directorys and prints them usage : printoverdues.sh directory [css [printer_host [printername]]] - directory directory to use to apply html2pdf transform - css css file to apply to html - printer_host Network Name or IP of the printer (port possibly included) - printer_name printername Note that css printerhost and printername are optional parameters Note that this script uses xhtml2pdf command xhtml2pdf command comes with pisa (a python library) To install you need setuptools library for python then type easy_install pisa --- misc/cronjobs/printoverdues.sh | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 misc/cronjobs/printoverdues.sh diff --git a/misc/cronjobs/printoverdues.sh b/misc/cronjobs/printoverdues.sh new file mode 100755 index 0000000000..3cf1c3d4a2 --- /dev/null +++ b/misc/cronjobs/printoverdues.sh @@ -0,0 +1,46 @@ +#!/usr/bin/bash + +print_usage(){ + echo "$0 : generates PDF files from html files in directorys and prints them"; + echo "usage :"; + echo "$0 directory [css [printer_host [printername]]]" + echo " - directory directory to use to apply html2pdf transform"; + echo " - css css file to apply to html "; + echo " - printer_host Network Name or IP of the printer (port possibly included) "; + echo " - printer_name printername "; + echo "Note that css printerhost and printername are optional parameters "; + echo "Note that this script uses xhtml2pdf command "; + echo " xhtml2pdf command comes with pisa (a python library) + To install you need setuptools library for python + then type easy_install pisa "; + + exit 1; +} +if [ $# -lt 1 ] +then + print_usage +fi +if [[ ! -d $1 ]] +then + echo "$1 : directory expected"; + exit 1; +fi +if [[ -n $2 && -f $2 ]] +then + set $optpisa "--css $2"; +fi +if [[ -n $3 ]] +then + set $optprinter "-h $3"; +fi +if [[ -n $4 ]] +then + set $optprinter "$optprinter -d $4"; +fi +for i in $1/*.html +do + xhtml2pdf $optpisa $i +done +lp $optprinter $1/*.pdf +tar cvfz $directory`date "+%Y%m%d"`.tar.gz $directory +rm -rf $directory -- 2.20.1