How to send data to a network printer using Perl on Win32?

I need to print relatively complex layouts to network / shared printers with Perl, and I haven't been able to find modules or examples to help me with the task. Anyone have any links that might help me?

I am assuming that what I want to do will work as Postscript.

update : Ok, I don't need help generating PDF or Postscript. I'm sure this is well documented. I want to know what I am using to send PDF to printer in windows from perl .

+2


source to share


4 answers


Ok, I still need to study the postscript or whatever, but I found that the following works:

use autodie;
use File::Copy;
copy 'C:\\frew.ps', '\\\\oxygen\\HPLJ5100 PCL6';

      



Not too hard. This seems to work better than the open

printer and print

to it.

+3


source


Win32 :: Printer exposes the Win32 printing API, including printer selection and low-level print commands.



However, (IMHO) an easy way to print a PDF file to any printer was to use Ghostscript to output PCL or PS (depending on the language the printer is supported in) and then to the copy

resulting file to the printer (using its UNC path). You may need to specify a switch /b

for the command copy

.

+3


source


If you have a PDF file and the user has Adobe Reader installed (which is pretty standard), you should be able to print the file to the default printer using ShellExecute in Win32 :: FileOp :

use Win32::FileOp 'ShellExecute';

ShellExecute(print => 'A:/Path/to/File.pdf');

      

+2


source


Wx :: Perl has very nice, licensed Win32 pinning capabilities.

I haven't worked with Postscript or PDF from WxPerl, so I don't know what will be involved. Googling wxPerl print pdf turns this post into a wxperl list .

Subject: Re: [wxperl-users] print PDF from wxPerl Actions ... From: Mark Dootson (mark ... @ znix.com) Date: Apr 5, 2007 5:02:40 pm List: org.perl.wxperl -users

Hello,

After writing the last answer, a huge kludge occurred to me that, as it turns out, it works just fine.

use Wx :: ActiveX :: IE to pass url to your pdf file and print fun. eg.

 my $obj = Wx::ActiveX::IE->new( $frame, -1, wxDefaultPosition, wxDefaultSize );
 $obj->LoadUrl("file:///C:/mytest.pdf");
 $obj->Print(0); # for no print dialog
 $obj->Print(1); # for print dialog

      

Sure, downloading IE and the Acrobat plugin might seem a bit overwhelming just to print the document, but heck it's windows and four lines of code pretty impressive.

Mark

This command line program can be another option. I haven't tried and can't vouch for it, but it claims to work for printing postscript data for headerless printers.

-1


source







All Articles