Updated smbprint.sysv.pcl

Kevin Pendleton kevin at electron-pc.com
Fri Jun 28 13:08:28 GMT 2002


Last month I submitted to the list a new version of smbprint.sysv which 
embeds PCL commands into the file prior to printing to add greater 
control over the printed document.  I have yet to hear back on it from 
anyone in the samba group so I'm not sure if the current version still 
needs this or not.  The reason I wrote it was for a company that still 
uses 1.9.17 on NCR MPRAS servers -- probably because nothing newer will 
compile on it.  Anyway, I am submitting it again with a few minor 
changes.  This script has only been tested on MPRAS with HP printers, 
but should work in any SYSV printing version of UNIX.  The changes are 
included in the script documentation as well as instructions for use. 
 The biggest change is the use of  \e instead of the literal escape 
character.

Let me know if you have any questions,

Kevin Pendleton
kevin at electron-pc.com

smbprint.sysv.pcl begins below:
________________________

#! /usr/bin/perl

############################################################################
# Version 2.1
#
# A new version of smbprint.sysv for Samba printing from UNIX to NT
#   based off of smbprint.sysv version 1.0 - 13 January 1995
#   by Ross Wakelin <r.wakelin at march.co.uk> which was a modification of
#   the original smbprint (bsd) script
#
#       Created by Kevin Pendleton - April 29, 2002
#                     (kevin at electron-pc.com)
#
# This script is a mix of a printer interface script and a print filter.
# This uses PCL commands to specify certain options for your print job
# by using  the -o parameter on the command line
#
#        lp -d printer -o option1,option2 filename
#
# No options are required.  If the option is not specified it will default
# to the printer's default settings.
#   Possible options:
#       * small (16.67 CPI), medium (12 CPI), or large (10 CPI)
#       * portrait or landscape
#               * portrait66 or landscape66 for 66 lines per page
#       * legal or letter
#       * manual or tray
#
# This script uses the smbclient program to print through Samba to the
# specified server and service.  To add this to your lp system, copy this
# file to your Samba directory (/usr/local/samba/lib), modify the server,
# service, user and password variables and then execute the following
# command (as root):
#
#   lpadmin -pprintername -v/dev/null -i/usr/local/samba/lib/smbprint
#
# where printername is the name that the printer will be known as on your
# UNIX box.  This script is copied into your printer administration 
directory
# (/usr/lib/lp or /etc/lp) as a new interface (interface/printername) so if
# you change the script, remove the printer and then add it again.  After
# adding the printer you must enable and accept the printer (as root)
#
#       enable printername
#       accept printername
#
# Don't forget to set up the Windows box to share the printer with the
# username and password that you specify below.
#
# Change Log:
#
# 06/28/02 - Replaced the literal escape character with \e (perl escape).
# 06/12/02 - Added umask 0 to make sure everyone can write to logs
############################################################################

# Change these values to your specific situation
# It's usually best to have the server and service is all caps
$server = "SERVER";
# Usually the service needs to be just one word
$service = "SHARENAME";
$log = "/tmp/$server.log";
$olog = "/tmp/$server.old";
$tmpfile = "/tmp/printfile";
$user = "username";
$password = "password";

############################################################################
# Don't change anything below here, except to remove CR/LF translation
# $new="print -\n";
$new="translate\nprint -\n";

# Rotate the logs
umask 0;
system("cp /dev/null $tmpfile");
system("mv $log $olog");

@val=@ARGV;

# Check for -o parameters
# First strip out flist info to prevent filenames from
# becoming options on accident.  You don't want a file
# named small to print small...
$params = $val[4];
$params =~ s/flist=\'(.*?)\s\'//;

# Check for paper size option
if ($params =~ /letter/){ $size = "2a"; }
elsif ($params =~ /legal/){ $size = "3a"; }

# Then check for paper source option
if ($params =~ /manual/){ $source = "2h" }
elsif ($params =~ /tray/){ $source = "4h" }

# Then check for paper orientation and VMI
# (Vertical Motion Index - lines per page)
if ($params =~ /landscape66/){ $orient = "1o5.45c" }
elsif ($params =~ /landscape/){ $orient = "1o" }
elsif ($params =~ /portrait66/){ $orient = "0o7.27c" }
elsif ($params =~ /portrait/){ $orient = "0o" }

# Finally check for font to use
if ($params =~ /small/){ $font = "\e(s0p16.67h0T"; }
elsif ($params =~ /medium/){ $font = "\e(s0p12h3T"; }
elsif ($params =~ /large/){ $font = "\e(s0p10h3T"; }

if ($size || $source || $orient) {
        $header = "\e&l";
        if ($size){ $header .= $size; }
        if ($source){ $header .= $source; }
        if ($orient){ $header .= $orient; }
        # Change the last letter to a capital
        $last= substr($header, -1, 1);
        # Fulfill rules of PCL
        $last = "\U$last";
        $header = substr($header, 0, -1) . $last;
}
if ($font){ $header .= $font; }

# add the header and footer with the file in the middle for each file
$index = 5;
while ($val[$index]){
        $new .= $header;
        $new .= `cat $val[$index]`;
        $new .= "\eE\n";
        open (PRINTFILE, "> $tmpfile");
        print PRINTFILE $new;
        close (PRINTFILE);
        $index++;
}

# Now send file(s) to the printer through Samba
$rc = `cat $tmpfile | /usr/local/samba/bin/smbclient 
\"\\\\\\$server\\$service\" $password -N -P -U$user >> $log`;

exit $rc;






More information about the samba-technical mailing list