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

I've had a request to create a program that reviews a DB of values that can be converted into URL requests - then proceed to the URL and print the first page of the HTML document (as presented, not with markup). I've gotten the code to print normally - but I don't want to be singly responsible for razing the rain forest just to get the first page of the website (not to mention the $$$ cost of that waste...). A sample of the code is below:
use strict; use Getopt::Long; use Win32::OLE qw( EVENTS with in ); use Win32::OLE::Variant; use Win32::OLE::Enum; ###################################################################### +########## # Enumerated IE Values ###################################################################### +########## use constant OLECMDID_PRINT => 6; use constant OLECMDID_SAVE => 3; use constant OLECMDID_SAVEAS => 4; use constant OLECMDID_OPEN => 1; use constant OLECMDEXECOPT_DEFAULT => 0; use constant OLECMDEXECOPT_PROMPTUSER => 1; use constant OLECMDEXECOPT_DONTPROMPTUSER => 2; ###################################################################### +########## # Option Variable Declaration ###################################################################### +########## my %args; ###################################################################### +########## # Process Command Line Options ###################################################################### +########## GetOptions( \%args, "help!" => sub { f_usage() }, ); ###################################################################### +########## # Global Variable Declaration and Setting ###################################################################### +########## my $Application = "InternetExplorer.Application"; $| = 1; ###################################################################### +########## # Function Declaration ###################################################################### +########## sub f_usage { print "Usage: " . __FILE__ . "\n"; exit 0; } ###################################################################### +########## # Main Process ###################################################################### +########## my $IE = Win32::OLE->new( $Application ) || die "$0: Could not start: $Application - $@, $!\n"; $IE->{Visible} = 1; while ( <DATA> ) { chomp; $IE->Navigate( $_ ); while ( $IE->Busy() ) { sleep 2; } $IE->ExecWB( OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER ); sleep 5; while ( $IE->Busy() ) { sleep 2; } } $IE->Quit(); exit; __DATA__ my.yahoo.com
This is the version that prints all pages (rainforest not-so-friendly). Again - I want to know how to default this to just 1 page. Any and all help appreciated. -Michael

Replies are listed 'Best First'.
Re: Controlling IE Printing from a Win32::OLE object
by planetscape (Chancellor) on May 26, 2006 at 04:04 UTC

    Untried, untested, but perhaps you should take a look at Win32::IE::Mechanize...

    Update: OK, on doing some further digging, I don't think Win32::IE::Mechanize is going to help you.

    I think what you want to do is have a close look at Reusing MSHTML, particularly what it has to say about Print Templates:

    To customize printing and the Print Preview feature introduced in Internet Explorer 5.5, use the IDM_PRINT and IDM_PRINTPREVIEW commands to pass the URL of a custom print template to MSHTML. Print templates give you control over the way MSHTML prints a document; they also offer control over the UI features provided in print preview mode.

    HTH,

    planetscape