Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Firefox equivalent to Win32:OLE?

by rsilvergun (Acolyte)
on Jun 20, 2007 at 00:04 UTC ( #622152=perlquestion: print w/replies, xml ) Need Help??

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

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 ;/.

Replies are listed 'Best First'.
Don't know if it'll be of use to anyone
by rsilvergun (Acolyte) on Jun 20, 2007 at 03:23 UTC
    But one quick and dirty trick I think I may end up using, just to get my immediate script working, is using raw postscript generated by a postscript printer printing to file (I used the HP Laserjet III Postscript Plus driver under Windows). It's easy enough to modify and fix it with perl, but I'm still partial to HTML. I like the idea of building the reports on the fly (w/o learning Postscript :) ) But Postscript works great for building simple text templates. What I'll actually ended up doing, I'm embarrassed to say, is printing my html in firefox to a file on a postscript printer, filling out the text fields with X's and then replacing the fields in my script with a s/// :). At least I don't have to build the postscript by hand.
Re: Firefox equivalent to Win32:OLE?
by ForgotPasswordAgain (Priest) on Jun 20, 2007 at 10:33 UTC

    If the layout is important, you might want to rethink whether using HTML to generate your reports is a good idea.

    I don't think you'll find a way to print a Gecko-rendered page without opening a browser window, for example through XPCOM, but let me know otherwise.

Re: Firefox equivalent to Win32:OLE?
by rsilvergun (Acolyte) on Jun 21, 2007 at 04:27 UTC
    I found perl's libwww-perl (the LWP), and it's got a module called HTML::FormatPS for rendering HTML to postscript. When I get time I'll play with it, but I just started a new job so that'll have to wait :/. Anyone used it and know how well it works (or if it does)?
      Looks like HTML::FormatPS is going to be a little to basic, not surprisingly :/. It does work, and work well on basic HTML, but it doesn't handle image tags (can't say I blame it :) ). I will persevere though.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2021-06-22 18:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (108 votes). Check out past polls.

    Notices?