[Samba] Re: Problem with pdf printing (SOLVED)

Luca Olivetti luca at wetron.es
Thu Mar 31 13:05:57 GMT 2005

Urs Rau wrote:
> Luca,
> Luca Olivetti wrote:

>> I don't know, but I bypassed the problem by using a pdf backend in 
>> cups (which is really a simple shell script that I tailored to my 
>> needs), so even the pdf printer is a "normal" cups printer.
> Somebody called "misty" said the same thing in IRC #samba yesterday, but 
> they had to run before they could show me the contents of the file. 
> Would you mind sending this to the list? I think it is still at least 
> slighlty "on-topic".

I already replied privately since I saw your personal message first, 
anyway, here it is again.

My cups distribution (mandrake 10.0) already came with a cups backend in 
  /usr/lib/cups/backend, this is my modified copy. Note that I don't 
export the users' home directory but the 'export' subdirectory in their 
home, so the script puts the generated pdf there or, if exists, in a pdf 
subdir. Users will see their file in the U: drive (that's mapped to 
their export dir) and there's no need to use a cron job to notify them 
since they can see if the job is still pending in the windows printer queue.
OTOH I had to upgrade ghostscript (to 8.15) since the stock one in mdk 
10.0 would choke on many ps files.

Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007
-------------- next part --------------
# 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 (goffioul at imec.be) 2001
PDFBIN=`which ps2pdf`
# 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 

# case of no argument, prints available URIs
if [ $# -eq 0 ]; then
	if [ ! -x "$PDFBIN" ]; then
		exit 0
	echo "direct pdf \"Unknown\" \"PDF Writing\""
	exit 0

# case of wrong number of arguments
if [ $# -ne 5 -a $# -ne 6 ]; then
	echo "Usage: pdf job-id user title copies options [file]"
	echo "Usage: pdf job-id user title copies options [file]" >> $LOGFILE
	exit 1

# get PDF directory from device URI, and check write status
if [ "$2" != "" ]; then
	USER=`echo "$2" | tr '[:upper:]' '[:lower:]'`
        PDFDIR=`getent passwd "$USER" | awk -F: '{print $6}'`
	if [ -d "${PDFDIR}/pdf" ]; then
if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then
	echo "ERROR: directory $PDFDIR not writable"
	echo "ERROR: directory $PDFDIR not writable" >> $LOGFILE
	exit 1

echo "PDF directory: $PDFDIR" >> $LOGFILE 

# generate output filename
if [ "$3" = "" ]; then
	TITLE=`echo $3 | sed -e 's/^smbprn\.[0-9]* //'`
	# I changed this to user name, and the printtime to track down who
	# printed the PDF and when, samba printing just uses nobody

	echo "PDF file: $OUTPUTFILENAME placed in: $PDFDIR" >> $LOGFILE

echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE 

# run ghostscript
if [ $# -eq 6 ]; then
#>& /dev/null
	$PDFBIN - "$OUTPUTFILENAME" >& /dev/null

# modify ownership and permissions on the file
#  - world readable
#  - owns to user specified in argument
#chmod a+r "$OUTPUTFILENAME"
if [ "$2" != "" ]; then
	chown "$2" "$OUTPUTFILENAME"

exit 0

More information about the samba mailing list