views:

421

answers:

4

I need to print relatively complex layouts to networked/shared printers with Perl and I haven't had any luck finding modules or examples to help me in the task. Does anyone have any links that could help me out?

I presume that what I want to do will work as Postscript.

update: Ok, I don't really need help with how to generate PDF or Postscript. I'm sure that's well documented. What I want to know is, what do I use to send a PDF to a printer in windows from perl.

+2  A: 

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 the ShellExecute function in Win32::FileOp:

use Win32::FileOp 'ShellExecute';

ShellExecute(print => 'A:/Path/to/File.pdf');
cjm
That's good, but I need to be able to print to more than just one printer. I'll look at the Win32::FileOp stuff though.
Frew
+3  A: 

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

However, the (IMHO) easy way of printing a PDF file on any printer would be to use Ghostscript to produce PCL or PS output (depending on the language the printer supports) and then to copy the resulting file to the printer (using its UNC path). You may need to specify the /b switch for the copy command.

Sinan Ünür
A: 

Wx::Perl has very nice, liberally licensed Win32 pinting capabilities.

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

Subject: Re: [wxperl-users] printing a PDF from wxPerl Actions... From: Mark Dootson ([email protected]) Date: Apr 5, 2007 5:02:40 pm List: org.perl.wxperl-users

Hi,

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

use Wx::ActiveX::IE pass it the URL of your pdf, and print merrily. e.g.

 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

Of course, loading IE and the Acrobat plugin may seem a little excessive just to print a doc, but heck, this is windows and four lines of code is pretty impressive.

Mark

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

daotoad
+1  A: 

Ok, I still need to learn postscript or something, but I found that the following works:

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

Not too complicated. This seems to work better than opening the printer and printing to it.

Frew