#!/bin/bash # # This is a modification of the pdfdistiller script to handle using SMB to # transfer the generated PDF file to a shared folder, so that host # (running windows) can watch the folder, and print what gets put into it # using the windows printer drivers. This way, you don't need ANY linux # support to print to the printer, as long as you have a windows PC to # attach it to and install the windows drivers on # # This script is intended to be used as a CUPS backend, to create # PDF file on-the-fly. Just create a printer using the device uri # pdf:/path/to/dir/. When printing to this printer, a PDF file # will be generated in the directory specified. The file name will # be either ".pdf" or "unknown.pdf", depending wether the # jobname is empty or not. # # To use it, simply copy this script to your backend directory, and # create a printer with the correct URI. That's it. # # Copyright (C) Michael Goffioul (kdeprint swing be) 2001 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA LOGFILE=/tmp/winp.log SPOOLDIR=/var/spool/winp SMBBIN=`which smbclient` SMBUSER=print SMBPASS=print FILENAME= # this is borrowed from printpdf script for the filename PRINTTIME=`date +%m%d-%H%M%S` echo "Arguments: |$1|$2|$3|$4|$5|$6|" >> $LOGFILE echo $# $PRINTTIME >> $LOGFILE # case of no argument, prints available URIs if [ $# -eq 0 ]; then echo "direct winp \"Unknown\" \"Windows Printing\"" exit 0 fi # case of wrong number of arguments if [ $# -ne 5 -a $# -ne 6 ]; then echo "Usage: winp job-id user title copies options [file]" exit 1 fi # get PDF directory from device URI, and check write status PDFDIR=${DEVICE_URI#winp:} #if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then # echo "ERROR: directory $PDFDIR not writable" # exit 1 #fi echo "PDF share: $PDFDIR" >> $LOGFILE # generate output filename OUTPUTFILENAME= if [ "$3" = "" ]; then OUTPUTFILENAME="unknown.ps" else # OUTPUTFILENAME="$PDFDIR/${3//[^[:alnum:]]/_}.pdf" # I changed this to user name, and the printtime to track down who # printed the PDF and when, samba printing just uses nobody OUTPUTFILENAME="$2-$PRINTTIME.ps" echo "PDF file: $OUTPUTFILENAME placed in: $PDFDIR" >> $LOGFILE fi echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE # run ghostscript if [ $# -eq 6 ]; then cp $6 "$SPOOLDIR/$OUTPUTFILENAME.tmp" #>& /dev/null else cat - > "$SPOOLDIR/$OUTPUTFILENAME.tmp" fi # copy the file to the SMB share echo smbclient -N $PDFDIR -c \'put $OUTPUTFILENAME.tmp\' >>$LOGFILE cd $SPOOLDIR smbclient $PDFDIR $SMBPASS -U $SMBUSER -c "put $OUTPUTFILENAME.tmp" >> $LOGFILE if [ "$?" -gt 0 ] then echo "Error: Can't copy PDF to $PDFDIR" >> $LOGFILE exit 1 fi # rename to .pdf so it gets picked up # without this step, file may get picked up while not fully transferred echo smbclient -N $PDFDIR -c "rename $OUTPUTFILENAME.tmp $OUTPUTFILENAME" >> $LOGFILE smbclient $PDFDIR $SMBPASS -U $SMBUSER -c "rename $OUTPUTFILENAME.tmp $OUTPUTFILENAME" >> $LOGFILE #delete file rm $OUTPUTFILENAME.tmp exit 0