On 2/24/10 Wed  Feb 24, 2010  11:49 AM, "boll" <b...@sonic.net> scribbled:

> Hello-
> 
> I am hoping there is a way to print HTML documents from a perl script.
> 
>     #!/usr/bin/perl -w
>     use strict;
>     use warnings;
>     print "Content-Type: text/html\n\n";
>     open HTML, "table_one.html" or die $!;
>     while( <HTML> ) {
>         print;
>     }
>     close HTML;
> 
> This displays the HTML code in the terminal window, but I need to
> produce the rendered page on a printer.
> Is there a module that will create printable HTML,
> or maybe a system or exec command that will print the documents?
> 
> These are plain HTML tables, so I don't need beautiful formatting.

Printing directly from a Perl program can be tricky, because doing so
depends heavily on your operating system and exact printer. You might be
able to open your printing as an output file and send data directly to it.
However, at best you might get the raw HTML text output with no formatting.
Most printers understand some sort of printer control language, such as
HPGL, Postscript, or PDF. Printers do not understand HTML.

You can output your HTML to a file, and print that file. Rather than sending
it directly to the printer, you can get it rendered as HTML by viewing in a
browser and printing the file from the browser.

That will work for a small number of files. If you want to automate the
process, then you need to either convert the HTML to a printer-ready file,
or automate sending the file to a browser.

For the former, search CPAN (<http://search.cpan.org>) for HTML conversion
files. For example, there is HTML::FormatPS that claims to convert HTML to
Postscript, but it doesn't do tables.

For the latter, there are HTML::Display modules on CPAN that claim to send
your output to a browser.

There is also the html2ps program: <http://user.it.uu.se/~jan/html2ps.html>

Rendering HTML is not easy, so your hopes may be hard to satisfy.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to