I'm working on a news "portal" site for one of my public Open Source projects, and have a question about PDF output.

Basically I have articles stored in a MySQL database which have some basic HTML formatting elements built into their body. These are not "webpages" per se, since there is no opening or closing <head> or <body> tags, just simple paragraph, bold, lists, and formatting elements. Here's a small example (note, this is the entire article as queried from the database):

<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>

When the user selects to read these articles, the articles is put between the "slices of bread" which adds my header and footer elements, according to the layout of the site, and the article body goes in middle.

What I'd like to do is provide a link at the bottom of each article that says "Convert to PDF" and have it link to a sub that can stuff this article into a PDF and present it to the user for view/download.

I have all of the mechanical bits of the query, response, display, etc. working, but need to know if it's possible with the various PDF modules (Text::PDF, PDF::Create, Data::Dbf2pdf, PDFLib) style modules take this article input and convert it into a usable PDF file, retaining the formatting that the HTML provides.

All of the examples I've seen deal with only plain text, not images or HTML-formatted text. I'm not opposed to doing some s/<li>/   o/ stuff where required, but I'd like to eliminate the need to do that kind of barbaric conversion.

edited: Wed Jul 24 16:30:15 2002 by jeffa - fixed closing li tag typo per author's request


In reply to HTML input to PDF output by hacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.