Stephen Patterson > Printer > Printer

Download:
Printer-0.98.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  2
Open  0
View/Report Bugs
Module Version: 0.98   Source  

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 and some changes to make it work with windows 2000 and XP.

SYNOPSIS ^

 use Printer;

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

or for windows network printers $prn = new Printer('MSWin32' => '\\server\printer')

 $prn->print_command('linux' => {'type' => 'pipe',
                                'command' => 'lpr -P lp'},
                    'MSWin32' => {'type' => 'command',
                                 'command' => 'gswin32c -sDEVICE=mswinpr2
                                 -dNOPAUSE -dBATCH $spoolfile'}
                    );

 %available_printers = $prn->list_printers;

 $prn->use_default;

 $prn->print($data);

Special options for print_command under Windows

 $prn->print_command('MSWin32' => {'type' => 'command',
                                  'command' => MS_ie});

Under Windows, the print_command method accepts the options MS_ie, MS_word and MS_excel to print data using Internet Explorer, Word and Excel.

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.

If you intend to use the use_default() or print_command() methods, you don't need to supply any parameters to new().

Printer ports and network printers under windows

To use a printer which is directly attached to your network, you need to share that printer from a windows host, otherwise you will just get a file which contains the print job in the perl script's directory.

This method dies with an error message on unsupported platforms.

Define a printer command to use

 $prn->print_command('linux' => {'type' => 'pipe',
                     'command' => 'lpr -P lp'},
                     'MSWin32' => {'type' => 'file',
                                  'command' => 'gswin32c -sDEVICE=mswinpr2
                                  -dNOPAUSE -dBATCH $spoolfile'}
                    );

This method allows you to specify your own print command to use. It takes 2 parameters for each operating system:

type

command

This specifies the command to be used.

Select the default printer

 $printer->use_default;

This should not be used in combination with print_command.

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 just-about works).

List available printers

 %printers = list_printers().

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

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).

NOTES ON THE WINDOWS AND LINUX/UNIX PRINT SPOOLERS ^

(Or why this will work better on Linux/UNIX than windows)

The Linux and UNIX printing systems are based around postscript and come with a set of ancillary programs to convert anything which should be printable into postscript. The postscript representation of your print job is then converted into a set of printing commands which your printer can recognise.

Windows printing is based on applications wanting to print using windows API calls (hideous) to create a GDI file which is then converted by the print spooler into printer specific commands and sent to the physical printer.

What this means to a user of the Printer module is that on Linux/UNIX the data passed to the print method can be anything which should be printable, i.e. groff/troff, PostScript, plain text, TeX dvi, but on windows the only data which can be handled by the printing system is plain text, GDI commands or flies written in your printer's interface language, though 0.98 adds the ability to print data using Microsoft's Internet Explorer, Word and Excel via OLE.

BUGS ^

AUTHORS ^

Stephen Patterson (steve@patter.mine.nu)

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

TODO ^

Changelog ^

0.98

0.97a, 0.97b, 0.97c, 0.97d

0.97

0.96

0.95c

0.95b

0.95a

0.95

0.94c

0.94b

0.94a

0.94

0.93b

0.93a

0.93

0.92

0.91

0.9

Initial release version

syntax highlighting: