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

(jeffa) Re: HTML input to PDF output

by jeffa (Bishop)
on Jul 24, 2002 at 15:50 UTC ( [id://184901]=note: print w/replies, xml ) Need Help??


in reply to HTML input to PDF output

A limited solution (no table or frame support) is the Cookbook's Recipe 20.5:
use strict; use HTML::FormatText; use HTML::Parse; my $data = do {local $/;<DATA>}; my $html = parse_html($data); my $formatter = HTML::FormatText->new( leftmargin => 0, rightmargin => 50, ); my $ascii = $formatter->format($html); print "$ascii\n"; __DATA__ <p class="fol">Here's some text that goes in the body of the article. It has some list items like this:</p> <ul> <li>List item one</li> <li>List item two</li> </ul>
This generates the following output:
Here's some text that goes in the body of the
article. It has some list items like this:

  * List item one

  * List item two

I have found that converting HTML to text is hard, and the best free tool i have found so far is lynx -dump. Of course, the most optimal solution is to never mix presentation with data! :)

Update: in case you are wondering where that extra bullet came from, it is the result of the closing li tags. Looks like HTML::FormatText could use an upgrade to support XHTML. -- good catch Hero Zzyzzx! ;) I fixed this typo since hacker requested i fix the original. For historical purposes, the first list item looked like so: <li>List item one<li>.

jeffa

Remember kids, just say no to mixing data and presentation!

Replies are listed 'Best First'.
Re: (jeffa) Re: HTML input to PDF output
by Hero Zzyzzx (Curate) on Jul 24, 2002 at 16:26 UTC

    Not to niggle, but one of the closing li tags isn't really a closing tag-
    <li>List item one<li>
    Note the second li.

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://184901]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-26 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found