Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Printing a page using win32::OLE and Internet Explorer

by slloyd (Hermit)
on Mar 09, 2010 at 22:27 UTC ( [id://827639]=perlquestion: print w/replies, xml ) Need Help??

slloyd has asked for the wisdom of the Perl Monks concerning the following question:

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; } }
s/te/ve/

Replies are listed 'Best First'.
Re: Printing a page using win32::OLE and Internet Explorer
by Anonymous Monk on Mar 10, 2010 at 01:02 UTC
      Thanks a bunch!
      s/te/ve/
        So what documentation were you looking at?
Re: Printing a page using win32::OLE and Internet Explorer
by Anonymous Monk on Mar 10, 2010 at 00:57 UTC
    I cannot figure out how to print though. Any suggestions?

    What documentation are you looking at?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://827639]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-24 17:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found