Hi everyone. I've been looking into the subject of "printing" to PDF with Samba in the last couple of days. Sorry to say that I wasted some time trying to figure out why the [print-pdf generator] in smb.conf didn't work. As always reading every comment carefully will pay off in terms of time wasted! After I realized that with printing = cups in smb.conf samba ignores any print command directive in a share I started looking for a solution.~ Some web searching tossed up a reference to setting printing = bsd on the specific share to make print command relevant. The only problemwas that it also mentioned Samba 3.03... I'm using 3.02a but decided to give it a try, no luck. So I decided to look to CUPS for an answer. I found that CUPS has the ability to use diferent backend processes to printing, one of them included is a backend called ... pdf. After checking the script of this backend I found it worked, but was not what I would like after looking at the possibilities in print-pdf. It always puts the output file in the same location and there is no notification to the user that it has finished and where the file is. So I started making some changes and I've got a working version that puts the output file in the user's home directory and notifies him like print-pdf does. You can find the script below, I've put all changes I made between comment lines like #EMR. If anyone would like to use these changes feel free to do so, if you enhance them please return me a copy of the improved version. Regards, Eugenio Ruivo #!/bin/sh
# # 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 "<jobname>.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 ([EMAIL PROTECTED]) 2001 # # 2004-08-25, Eugenio Ruivo # Made changes to try and identify user's home directory and place output # file there instead of default location. # Also send notification to user that file has "printed", to where and what name. # Since my users are in LDAP backend try to lookup Windows homedrive letter to use in # notification message else notifies with full server path to home directory. # LOGFILE=/tmp/pdf.log PDFBIN=`which ps2pdf` FILENAME= # this is borrowed from printpdf script for the filename PRINTTIME=`date +%b%d-%H%M%S` echo "Executable: $PDFBIN" > $LOGFILE echo "Arguments: |$1|$2|$3|$4|$5|$6|" >> $LOGFILE echo $# $PRINTTIME >> $LOGFILE #EMR USER_ER=$2 JOB_ER=$1 ORIGIN_ER=`smbstatus -b -u $2|grep $2` HOMEDIR_ER=`eval "echo ~$2"` echo "" >> $LOGFILE echo "Script Run by: $USER" >> $LOGFILE echo "User is: $USER_ER" >> $LOGFILE echo "Job Id is: $JOB_ER" >> $LOGFILE echo "Origin is from: $ORIGIN_ER" >> $LOGFILE echo "User's HomeDir is: $HOMEDIR_ER" >> $LOGFILE echo "" >> $LOGFILE PID_ER=`echo $ORIGIN_ER | cut -f1 -d ' '` USERID_ER=`echo $ORIGIN_ER | cut -f2 -d ' '` GROUPID_ER=`echo $ORIGIN_ER | cut -f3 -d ' '` COMPUTER_ER=`echo $ORIGIN_ER | cut -f4 -d ' '` IP_ER=`echo $ORIGIN_ER | cut -f5 -d ' ' | sed 's/(//' | sed 's/)//'` echo "PID is: $PID_ER" >> $LOGFILE echo "UserID is: $USERID_ER" >> $LOGFILE echo "Group ID is: $GROUPID_ER" >> $LOGFILE echo "Computer is: $COMPUTER_ER" >> $LOGFILE echo "IP Address is: $IP_ER" >> $LOGFILE #EMR # case of no argument, prints available URIs if [ $# -eq 0 ]; then if [ ! -x "$PDFBIN" ]; then exit 0 fi echo "direct pdf \"Unknown\" \"PDF Writing\"" exit 0 fi # case of wrong number of arguments if [ $# -ne 5 -a $# -ne 6 ]; then echo "Usage: pdf job-id user title copies options [file]" exit 1 fi #EMR if [ "$HOMEDIR_ER" = ""]; then #EMR # get PDF directory from device URI, and check write status PDFDIR=${DEVICE_URI#pdf:} #EMR else PDFDIR=$HOMEDIR_ER fi #EMR if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then echo "ERROR: directory $PDFDIR not writable" exit 1 fi echo "PDF directory: $PDFDIR" >> $LOGFILE # generate output filename OUTPUTFILENAME= if [ "$3" = "" ]; then OUTPUTFILENAME="$PDFDIR/unknown.pdf" 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 #EMR Change to title-printtime.pdf since we will write to user's home dir OUTPUTFILENAME="$PDFDIR/$3-$PRINTTIME.pdf" #EMR # OUTPUTFILENAME="$PDFDIR/$2-$PRINTTIME.pdf" echo "PDF file: $OUTPUTFILENAME placed in: $PDFDIR" >> $LOGFILE fi echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE # run ghostscript if [ $# -eq 6 ]; then $PDFBIN $6 "$OUTPUTFILENAME" #>& /dev/null else $PDFBIN - "$OUTPUTFILENAME" >& /dev/null fi # modify ownership and permissions on the file # - world readable # - owns to user specified in argument #EMR Change to only readable by user since it's in his homedir chmod 600 "$OUTPUTFILENAME" #EMR #chmod a+r "$OUTPUTFILENAME" if [ "$2" != "" ]; then #EMR Change owner and group also chown $USERID_ER.$GROUPID_ER "$OUTPUTFILENAME" #EMR # chown $2 "$OUTPUTFILENAME" fi #EMR Borrow idea from samba's print-pdf to notify user # Lookup home drive letter HOMEDRIVE_ER=`ldapsearch -x -LLL -b "ou=Users,ou=Samba,dc=spel-parques,dc=pt" "(uid=emruivo)" sambaHomeDrive | grep sambaHomeDrive: | cut -f2 -d ' '` # Check if we found our home drive in LDAP if [ $HOMEDRIVE_ER = ""]; then # Yes, give Windows style location of output file MESSAGE="Your PDF file has been created as:\n$OUTPUTFILENAME" else # Just give path to file MESSAGE="Your PDF file has been created as:\n$HOMEDRIVE_ER\\$3.pdf" fi echo -e $MESSAGE|smbclient -M $COMPUTER_ER -I $IP_ER -U "Print PDF Service" >/dev/null 2>&1 #EMR exit 0 -- To unsubscribe from this list go to the following URL and read the instructions: http://lists.samba.org/mailman/listinfo/samba