paul.dorman has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, upon discovering (to my horror) that Win32::Printer::Direct does not respect the configuration set in the Printers and Faxes dialogue (such as the source and output tray), I proceeded to look at using Win32::Printer do do the job.

The method that seems most promising is the Inject method, which appears to let you inject raw postscript data into the job. I would like to inject contents of the file I have so that it's data is the only thing that gets sent to the printer.

No matter what I have tried though, the page comes out blank.

Has anyone managed to use Win32::Printer to print a postscript file loaded from disk? I need to either specify the source and output tray, *or* have the current settings in the Printer and Faxes dialogue respected. I also don't want to have to share the printers as this would be politically incorrect where I work.

Examples would be very, *very* welcome.

Regards, Paul

  • Comment on Printing a postscript file with Win32::Printer

Replies are listed 'Best First'.
Re: Printing a postscript file with Win32::Printer
by Corion (Patriarch) on Jun 30, 2006 at 06:28 UTC

    I did this once by looking through the PostScript preamble, patching the tray selection code in the PostScript file and then sending the file directly to the printer (via ftp), because luckily the printer understood PostScript directly.

    This will obviously not work if you don't have native PostScript printers ...

      That sounds promising. So if I work out what PostScript to use for setting the MediaPostion attribute, and insert that into the file before printing, I could use Win32::Printer::Direct to print the page?

      I haven't yet found exactly where and how to use MediaPosition , but I'll provide you all an update when I do. :o)

Re: Printing a postscript file with Win32::Printer
by jdtoronto (Prior) on Jun 30, 2006 at 09:53 UTC
    paul.dorman

    I haven't used this module family but a colleague did some time back. From his notes you need to be wary of the control data which may already be in the PostScript. Corion alluded to that when he talked about fiddling the PS Preamble info!

    There is an enumerator module which allows you to get the info from the printer, you need to do that then feed that back into the Win32::Printer invocation.

    If you use the inject method you will have to make sure that you still have the PS Preamble and make sure to use the end method. In the code I am looking at (which is very long!) the inject method is used to load some graphics actually written in PostScript - not a complete PS page. Apart from that, how about some code we can look at?

    jdtoronto

Re: Printing a postscript file with Win32::Printer
by Ieronim (Friar) on Jun 30, 2006 at 17:43 UTC
    There is a freeware Win32 utility called PrintFile (http://www.lerup.com/printfile/).

    According to its documentation, it can read data to print from STDIN or from file, so it can be called directly from your script using system() :)

    It can be a faster and more reliable way to get your job done.

    HTH :)

      Nope, this doesn't work I'm afraid - it prints straight to the printer, ignoring any settings in the Printers and Faxes dialog. :o(
        Correction: PostScript option "Include driver header" works! Yay!