The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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. CUPS users will need to set up cups-lpd to provide legacy access. ( See "Using Net::Printer with CUPS" )

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 /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 and Security Implications

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!

Using Net::Printer with CUPS

Net::Printer, by itself, does not speak to printers running the CUPS protocol. In order to provide support for legacy clients, most modern CUPS distributions include the cups-lpd mini-server which can be set up to run out of either inetd or xinetd depending on preference. You will need to set up this functionality in order to use Net::Printer with a CUPS server.

AUTHOR

C. M. Fuhrman, cfuhrman@panix.com

SEE ALSO

cups-lpd, lp, lpr, perl

RFC 1179 http://www.ietf.org/rfc/rfc1179.txt?number=1179