Talk:Cups

From SME Server
Jump to: navigation, search

Robert, are you still maintaining this?

There is a bug report here - http://bugs.contribs.org/show_bug.cgi?id=6094 - that anyone following this howto may need to be aware of.

Also another bug report here - http://bugs.contribs.org/show_bug.cgi?id=5877



Here is an adaptation of the pdf printer that is installed by cups-pdfdistiller which won't drop the file in a certain folder on your server, but instead delivers it in the mailbox of the user who printed the file.

 #!/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 (kdeprint <at> swing <dot> 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=/var/log/pdf.log

   function log {
     if [ "$2" == "" ]; then
       echo $(date +%c) [notice] $1 >> $LOGFILE
     else
       echo $(date +%c) [$2] $1 >> $LOGFILE
     fi
   } 

   log "Executable: $PDFBIN"
   log "Arguments: |$1|$2|$3|$4|$5|$6|"

   # 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]"
     log "No arguments supplied" "error"
     exit 1
   fi

   # get PDF directory from device URI, and check write status
   PDFDIR=${DEVICE_URI#pdf:}
   if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then
     log "Directory \"$PDFDIR\" not writable" "error"
     exit 1
   fi

   PDFBIN=`which ps2pdf14`
   PRINTTIME=`date +%b%d-%H%M%S`
   print "PDF directory: $PDFDIR" >> $LOGFILE

   # generate output filename
   if [ "$3" = "" ]; then
     PDFFILENAME="$PDFDIR/unknown.pdf"
   else
     # PDFFILENAME="$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
     # PDFFILENAME="$PDFDIR/$2-$PRINTTIME.pdf"
     PDFFILENAME="$3.pdf"
   fi

   log "Output file name: $PDFDIR/$PDFFILENAME"

   # run ghostscript
   if [ $# -eq 6 ]; then
     $PDFBIN $6 "$PDFDIR/$PDFFILENAME"
   else
     $PDFBIN - "$PDFDIR/$PDFFILENAME" >& /dev/null
   fi

   MAILTIME=`date +%c`

   # Store users e-mailadress in variable named 'TO'
   # Username is received via the second argument of the modified printcommand of the PDF printer
   # append @yourdomain.com to create a valid email address

   DOMAIN=`/sbin/e-smith/db configuration get DomainName`
   TO=$2@$DOMAIN

   # Create a temp file to hold the mailbody
   # Available variables:

   # $1    - Job number
   # $2    - User name
   # $3    - Printjob name
   # $4    - Number of copies

   MAIL=$OUTDIR/$2$PRINTTIME.txt

   echo ""  >> $MAIL
   echo "Hello $2," >> $MAIL
   echo "Here's your requested PDF file." >> $MAIL
   echo "" >> $MAIL
   echo "Job Number   : pdf-$1" >> $MAIL
   echo "Title        : $3" >> $MAIL
   echo "Submitted at : $MAILTIME" >> $MAIL
   echo "Attached as  : $PDFFILENAME." >> $MAIL

   # Use mutt to generate an email containing the text above and has the PDF attached
   mutt -a "$PDFDIR/$PDFFILENAME" -i $MAIL -s "$3 (pdf-$1)" $TO
   log "PDF file \"$PDFFILENAME\" mailed to $TO"
   rm -rf $MAIL
   rm -rf "$PDFDIR/$PDFFILENAME"

   exit 0

You can easily install this script:

  1. Backup the original file;
    cp /usr/lib/cups/backend/pdf /usr/lib/cups/backend/pdf.old
    
  2. nano /usr/lib/cups/backend/pdf
    

    Paste the script there end save using Ctrl+O, after that exit with Ctrl+X.


    May be usesful add a reference to http://wiki.contribs.org/Printer_Drivers_for_Windows_Workstations

    --Normando Hall 09:38, 5 November 2007 (MST)