I have built a private intranet using perl and have upgrading the site to IIS 7.5 on Windows Server 2008 R2. I have a section that prints tags formatted with win32 Printer. I have gone through all the steps to get perl to work.

I was able to get this working with Server 2003. I basically had to create a user for perl to use in the group IIS_WPG so that perl would print to a local printer. I can print to the printer using a test script called from the command prompt but called from a browser you get this

HTTP Error 502.2 - Bad Gateway
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "ERROR: Cannot create printer object! þÿÿÿ8­w4­w at testprinter.pl line 4 ". Detailed Error Information
Module CgiModule 
Notification ExecuteRequestHandler 
Handler perl script map 
Error Code 0x00000009 
Requested URL testprinter.pl 
Physical Path testprinter.pl 
Logon Method Anonymous 
Logon User Anonymous

The test script that I am using is

#!perl
 use Win32::Printer;

my $dc = new Win32::Printer(
 printer => 'emtags',
            height          => 214,
            width           => 288,
            printer         => 'emtags',
            unit            => 'pt'
 );

my $font = $dc->Font('Arial Bold', 24);
 $dc->Font($font);
 $dc->Color(0, 0, 255);
 $dc->Write("Hello, Mars!", 50, 50);

$dc->End();
 $dc->Close();
 exit 0;

Thanks very much for your help with this.

Recommended Answers

All 9 Replies

Member Avatar for LastMitch

I was able to get this working with Server 2003. I basically had to create a user for perl to use in the group IIS_WPG so that perl would print to a local printer.

I assume you got that code from here:

http://search.cpan.org/~wasx/Win32-Printer-0.9.1/Printer.pm

The error you are having has nothing to do with PERL code.

The error that you got was a CGI issue meaning you don't have permission to access the header.

Thanks for your reply. I put in header code such as

print "Content-Type: text/html\n\n";

at the beginning I never see the error. Taking it our of putting it at the end I get the same error message. doesn't make it past line 5. There is also a duplicate line in the printer object that I have removed and it made no difference. the problem as I see it and this is sfter tracking it is that the user for iis is not allowed to print. This code works great from the command line but not from IIS.

Member Avatar for LastMitch

You mean this line:

printer => 'emtags',

Why do you have 2 :

printer => 'emtags'

There is also a duplicate line in the printer object that I have removed and it made no difference.

What is the acutally error now?

Yes that is the line and after removal it made absolutly no difference. I had hope when I saw it.

Member Avatar for LastMitch

Yes that is the line and after removal it made absolutly no difference. I had hope when I saw it.

Can you try this:

$dc->Debug([1]);

No it dies before it gets to the line. At the command prompt I get this error

ERROR: Argument "ARRAY(0x32f9354)" isn't numeric!
at testprinter.pl line 12

I put it in the test script right after the creation of the printer object. dies before then...

thought I would try carp fatals as well and get the same message.

Member Avatar for LastMitch

ERROR: Argument "ARRAY(0x32f9354)" isn't numeric! at testprinter.pl line 12

Is there another file? Line 12 is this: my $font = $dc->Font('Arial Bold', 24);

This is your code:

#!perl
use Win32::Printer;
my $dc = new Win32::Printer(
printer => 'emtags',
height => 214,
width => 288,
printer => 'emtags',
unit => 'pt'
);
my $font = $dc->Font('Arial Bold', 24);
$dc->Font($font);
$dc->Color(0, 0, 255);
$dc->Write("Hello, Mars!", 50, 50);
$dc->End();
$dc->Close();
exit 0;

Try this instead:

use Win32::Printer;

my $dc = new Win32::Printer(
papersize   => A4,
dialog      =>  ALLPAGES,
description => 'Hello, Mars!',
unit        => 'mm'
);

my $font = $dc->Font('Arial Bold', 24);
$dc->Font($font);
$dc->Color(0, 0, 255);
$dc->Write("Hello, Mars!", 10, 10);

$dc->Brush(128, 0, 0);
$dc->Pen(4, 0, 0, 128);
$dc->Ellipse(10, 25, 50, 50);

$dc->Close();

What error did you get?

It shouldn't be the same error.

You can try these tutorial:

http://legacy.websitepanel.net/kb/installing-and-running-active-perl-runtime-as-isapi-on-microsoft-iis-7.0

or this:

http://www.howtogeek.com/50479/how-to-install-perl-on-iis-7-for-windows-server-2008/

Those links is to show you how to installed and test Perl in window server 2008

Thanks very much for your post. I have found a portion of the problem. I can now print, the problem was authentication like I suspected. I had to change the user from Anonymous to an authenticated user. I disabled a lot of the other abilities but this was the main cure to the problem. However I have found that Win32::Printer is not printing lines or much in the way of formatting. Everything I had centered wanted to be left justified, lines and pictures out of the question.

Member Avatar for LastMitch

I have found a portion of the problem. I can now print, the problem was authentication like I suspected.

That's good you did. The code you provided didn't show Anonymous User or Authenticated user maybe the error message mention it. It's good you are making process.

I have found that Win32::Printer is not printing lines or much in the way of formatting. Everything I had centered wanted to be left justified, lines and pictures out of the question.

Can you post an image of that picture or post the small code snippet related to that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.