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/

In reply to Printing a page using win32::OLE and Internet Explorer by slloyd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.