NAME

Printer.pm - a low-level, platform independent printing interface (curently Linux and MS Win32. other UNIXES should also work.)

This version includes working support for Windows 95.

SYNOPSIS

 use Printer;
    
 $prn = new Printer('linux' => 'lp', 
	            'MSWin32' => 'LPT1', 
		    $OSNAME => 'Printer');

 %available_printers = $prn->list_printers;

 $prn->use_default;

 $prn->print($data);

DESCRIPTION

A low-level cross-platform interface to system printers.

This module is intended to allow perl programs to use and query printers on any computer system capable of running perl. The intention of this module is for a program to be able to use the printer without having to know which operating system is being used.

PLATFORMS

This code has been tested on Linux, DEC-OSF, Solaris, HP/UX windows 95 and windows NT4.

UNIX printing works using the Linux routines. This assumes that your print command is lpr, your queue list command is lpq and that your printer names can be found by grepping /etc/printcap. If it's anything different, email me with the value of $OSNAME or $^O and the corrections.

USAGE

Open a printer handle

 $printer = new Printer('osname' => 'printer port');
 $printer = new Printer('MSWin32' => 'LPT1', 
			'Linux' => 'lp');

This method takes a hash to set the printer name to be used for each operating system that this module is to be used on (the hash keys are the values of $^O or $OSNAME for each platform) and returns a printer handle which is used by the other methods.

This method dies with an error message on unsupported platforms.

Select the default printer

$printer->use_default;

Linux

The default printer is read from the environment variables $PRINTER, $LPDEST, $NPRINTER, $NGPRINTER in that order, or is set to the value of lpstat -d or is set to "lp" if it cannot be otherwise determined. You will be warned if this happens.

Win32

THe default printer is read from the registry (trust me, this works).

List available printers

%printers = list_printers().
   

This returns a hash of arrays listing all available printers. The hash keys are:

  • %hash{names} - printer names

  • %hash{ports} - printer ports

Print

$printer->print($data);

$printer->print(@pling);

Print a scalar value or an array onto the print server through a pipe (like Linux)

List queued jobs

@jobs = $printer->list_jobs();

This returns an array of hashes where each element in the array contains a hash containing information on a single print job. The hash keys are: Rank, Owner, Job, Files, Size.

This code shows how you can access each element of the hash for all of the print jobs.


 @queue = list_jobs();
 foreach $ref (@queue) {
     foreach $field (qw/Rank Owner Job Files Size/) {
	 print $field, " = ", $$ref{$field}, " ";
     }
     print "\n";
 }

Windows

The array returned is empty (for compatibility).

BUGS

  • list_jobs needs writing for win32

AUTHORS

Stephen Patterson (s.patterson@freeuk.com)

David W Phillips (ss0300@dfa.state.ny.us)

TODO

  • Make list_jobs work on windows.

  • Test and fully port to UNIX.

  • Port to MacOS.

Changelog

0.94b

  • added documentation of the array input capabilities of the print() method

0.94a

  • glaring typos fixed to pass a syntax check (perl -c)

0.94

  • uses the first instance of the lp* commands from the user's path

  • more typos fixed

  • list_jobs almost entirely rewritten for linux like systems.

0.93b

  • Checked and modified for dec_osf, solaris and HP/UX thanks to data from David Phillips.

  • Several quoting errors fixed.

0.93a

  • list_jobs returns an array of hashes

  • list_printers exported into main namespace so it can be called without an object handle (which it doesn't need anyway).

0.93

  • Printing on windows 95 now uses a unique spoolfile which will not overwrite an existing file.

  • Documentation spruced up to look like a normal linux manpage.

0.92

  • Carp based error tracking introduced.

0.91

  • Use the linux routines for all UNIXES.

0.9

Initial release version

1 POD Error

The following errors were encountered while parsing the POD:

Around line 573:

You forgot a '=back' before '=head2'