Frew Schmidt
Frew Schmidt

Reputation: 9544

How do I send data to a network printer with Perl on Win32?

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.

Upvotes: 2

Views: 3745

Answers (4)

Frew Schmidt
Frew Schmidt

Reputation: 9544

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.

Upvotes: 3

daotoad
daotoad

Reputation: 27193

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.

Upvotes: -1

Sinan Ünür
Sinan Ünür

Reputation: 118148

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.

Upvotes: 3

cjm
cjm

Reputation: 62109

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');

Upvotes: 2

Related Questions