I am trying to load a URL in IE and print it to a postscript printer using Win32::OLE. I cannot figure out how to print though. Any suggestions? The code below outputs the following:
URL: http://www.google.com/
Page Setup
URL: http://www.google.com/
Printing
Win32::OLE(0.1709) error 0x80070057: "The parameter is incorrect"
in GetIDsOfNames for "" at C:\Dev\Tools\AutomationTools\OfficeConverters\ie.pl line 29
--------------------------------------
#!/usr/bin/perl -w
use strict;
use Win32::OLE qw( EVENTS in with );
use Win32::OLE::Variant;
use Win32::OLE::Const 'Microsoft Office';
my $ie = Win32::OLE->new( 'InternetExplorer.Application' ) or die "err
+or starting IE";
$ie-> {menubar} = 1;
$ie-> {toolbar} = 1;
$ie-> {statusbar} = 1;
$ie->{visible} = 1;
sleep(2);
Win32::OLE->Option( Warn => 2 );
my $url=shift;
my $outfile="test.ps";
Win32::OLE->WithEvents( $ie, \&Event, 'DWebBrowserEvents2' );
$ie->navigate( $url );
Win32::OLE->MessageLoop();
print "Page Setup\n";
my $margin=$ie->Document->InchesToPoints("0.5");
with ($ie->Document->PageSetup,
'LeftMargin' => $margin,
'RightMargin' => $margin,
'TopMargin' => $margin,
'BottomMargin' => $margin,
'PrintHeadings'=>0,
);
print "Printing\n";
$ie->Document->Options(PrintBackground => 1);
$ie->Document->Print({
'PrintToFile' => 1,
'OutputFileName' => $outfile,
'Copies' => 1
});
print " - waiting for print to complete\r\n";
for (my $i = 0; $i < 600; $i++) {
sleep 1;
last unless $ie->Document->{BackgroundPrintingStatus};
}
print " - closing ie\r\n";
sleep 1;
$ie->Quit();
exit 0;
sub Event {
my ($Obj,$Event,@Args) = @_;
my $IEObject = shift @Args;
# STEP 1 : Find the main menu, login to the web site, find the tre
+eview
if ($Event eq "DocumentComplete" && $ie->Document->URL!~/^about\:b
+lank$/is) {
print "URL: " . $ie->Document->URL . "\n";
Win32::OLE->QuitMessageLoop;
}
}