Printing HTML via perl

miyagawa on 2006-08-02T02:46:46

lazyweb,

Suppose I have $url or $path_to_html, how can I print them as HTML rednered (probably using browser engine) via Perl? I imagine that it could be done using OLE/AppleScript thing, or using Mozilla command line option but couldn't find any code on the web nor CPAN.

I want solutions for Win32/IE, Win32/Firefox, MacOSX/Safari and MacOSX/Firefox.


HTMLDOC

saorge on 2006-08-02T07:25:14

Maybe HTML::HTMLDoc can help you !

Re:HTMLDOC

miyagawa on 2006-08-02T07:46:06

Thanks. I tested PDF::FromHTML as well and i guess these use the same idea behind. What I really want is to display HTML using real browser engines like IE/Firefox/Safari.

Thanks for your info anyway.

Re:HTMLDOC

pudge on 2006-08-09T06:29:43

Something like this, you mean?
use Mac::Glue;
use Mac::InternetConfig; # GetICHelper
use Mac::MoreFiles; # %Application
 
my($id) = GetICHelper('http');
my $app_path  = $Application{$id};  # or define path yourself ... this could potentially fail
my $file_path = '/Users/pudge/Desktop/a.html';
 
my $finder = new Mac::Glue 'Finder';
 
my $file = $finder->obj(file => $file_path);
my $app  = $finder->obj(file => $app_path);
 
$file->open(using => $app);

Re:HTMLDOC

miyagawa on 2006-08-09T06:33:50

Thanks! Yeah, this is very close, except you code doesn't look like actually "printing" the HTML document. I'd like to automate the print process as well.

Thanks for your code anyway. It's pretty helpful.

Re:HTMLDOC

pudge on 2006-08-09T06:51:13

Aha. Well, let's simplify by assuming Safari, then. Try:
use Mac::Glue;
 
my $file_url = 'file://localhost/Users/pudge/Desktop/a.html';
my $safari = new Mac::Glue 'Safari';
 
my $doc = $safari->make(new => 'document');
$doc->prop('url')->set(to => $file_url);
$doc->print;

Re:HTMLDOC

jrockway on 2006-09-05T03:43:42

WWW::Selenium might be what you want. Cross-platform too. Right now the interface is a bit rough, but I'm working on making it easier to use with Test::WWW::Selenium::Catalyst.

Python

stu42j on 2006-08-02T18:26:36

Here's some python code that might help point you in the right direction.

http://www.burtonini.com/blog/computers/mozilla-thumbnail-20040614.xhtml

Re:Python

stu42j on 2006-08-02T18:31:03

Here's another one in perl that exports to jpg, not sure if that is really what you are looking for.

http://marginalhacks.com/bin/html2jpg