NAME
Net::Printer - Perl extension for direct-to-lpd printing.
SYNOPSIS
use Net::Printer;
# Create new Printer Object
$lineprinter = new Net::Printer(
filename => "/home/jdoe/myfile.txt",
printer => "lp",
server => "printserver",
port => 515,
lineconvert => "YES"
);
# Print the file
$result = $lineprinter->printfile();
# Optionally print a file
$result = $lineprinter->printfile("/home/jdoe/myfile.txt");
# Print a string
$result =
$lineprinter->printstring("Smoke me a kipper, I'll be back for breakfast.");
# Did I get an error?
$errstr = $lineprinter->printerror();
# Get Queue Status
@result = $lineprinter->queuestatus();
DESCRIPTION
Perl module for directly printing to a print server/printer without
having to create a pipe to either lpr or lp. This essentially
mimics what the BSD LPR program does by connecting directly to the
line printer printer port (almost always 515), and transmitting
the data and control information to the print server.
Please note that this module only talks to print servers that
speak BSD. It will not talk to printers using SMB or SysV unless
they are set up as BSD printers.
Parameters
filename - [optional] absolute path to the file you wish to print.
printer - [optional] Name of the printer you wish to print to.
Default "lp".
server - [optional] Name of the server that is running
lpd/lpsched. Default "localhost".
port - [optional] The port you wish to connect to.
Default "515".
lineconvert - [optional] Perform LF -> LF/CR translation.
Default "NO"
rfc1179 - [optional] Use RFC 1179 compliant source address.
Default "NO". See below for security implications
Functions
printfile prints a specified file to the printer. Returns a 1 on success, otherwise returns a string containing the error.
printstring prints a specified string to the printer as if it were a complete file Returns a 1 on success, otherwise returns a string containing the error.
queuestatus returns the current status of the print queue. I recommend waiting a short period of time between printing and issuing a queuestatus to give your spooler a chance to do it's thing. 5 seconds tends to work for me.
printerror returns the error for your own purposes.
TROUBLESHOOTING
Stair Stepping Problem
When printing text, if you have the infamous "stair-stepping" problem, try setting lineconvert to "YES". This should, in most cases, rectify the problem.
RFC-1179 Compliance Mode
RFC 1179 specifies that any program connecting to a print service must use a source port between 721 and 731, which are reserved ports, meaning you must have root (administrative) privileges to use them. This is a security risk which should be avoided if at all possible!
AUTHOR
C. M. Fuhrman, chris.fuhrman@tfcci.com
SEE ALSO
Socket, lpr(1), lp(1), perl(1).