I'm writing some simple report generator/printers, and I used HTML to generate the reports, and now I'm trying to print them from my script. I found this nice little chunk of code to that will make Internet Explorer print my html page:
#!/usr/bin/perl
use strict;
use warnings 'all';
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Internet Controls';
use Win32::OLE::Variant;
# From Vc7/PlatformSDK/Include/MsHtmHst.h :
use constant PRINT_DONTBOTHERUSER => 0x01;
use constant PRINT_WAITFORCOMPLETION => 0x02;
my $file = "C:\\FixReportBase\\realtest\\pg_0001.htm";
my $do_not_prompt = 0;
my $nCmdID = OLECMDID_PRINT;
my $nCmdExecOpt = OLECMDEXECOPT_PROMPTUSER;
my $pvaIn = PRINT_WAITFORCOMPLETION;
my $pvaOut = 0;
if ($do_not_prompt) {
$nCmdExecOpt = OLECMDEXECOPT_DONTPROMPTUSER;
$pvaIn |= PRINT_DONTBOTHERUSER;
}
my $IE = Win32::OLE->new('InternetExplorer.Application') or die;
#$IE->{'Visible'} = 1;
$IE->Navigate( $file );
sleep 1 while $IE->{Busy};
$IE->ExecWB($nCmdID, $nCmdExecOpt, Variant(VT_I2,$pvaIn), $pvaOut);
$IE->Quit();
It works nicely trouble is IE's print engine sucks, and messes up the format of my report. I can foobar the HTML to make the report print nicely in IE, but I'm much rather just use Gecko/Firefox. Anyone know some way to get Firefox to print my HTML from perl (or offer up the print dialog for printing the HTML)? If all else really fails I can use javascript in my HTML to for a print and then call Firefox on it via System, but that's a pretty ugly hack, since it splashes a Firefox window on the screen ;/.