Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

"The web is not print"

by Kozz (Friar)
on Dec 12, 2001 at 22:08 UTC ( #131316=perlquestion: print w/replies, xml ) Need Help??

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

Most wise monks:

We all know that "the web is not print". That is to say that HTML-formatted documents and their cousins are NOT meant for printing in a paginated fashion as are StarOffice docs, and so forth. Though I've tried time and again to pound this fact into the brains of coworkers and clients alike, sooner or later they all still demand that I take abstract data in one form or another and create a miracle by which this data can be printed in a nicely formatted and paginated document.

More details: I've got a database which contains several tables making up a telephone directory for the company. It's got all the bells and whistles for doing lookups on various criteria and works fantastic through the browser. But now I'm told that they also want to be able to take all of the telephone directory contents and print it in a nicely formatted office-like document.

Here's where I get to the perl-related stage: does anyone know of ways to take data like this and use a Perl module that can create paginated documents? Or am I really up the creek without a paddle?

Thanks for reading.

Replies are listed 'Best First'.
Re: "The web is not print"
by mortis (Pilgrim) on Dec 12, 2001 at 22:22 UTC
    There are CPAN modules for creating and manipulating PDF, RTF, and PostScript. Which should be good formats for creating printable documents.
Re: "The web is not print"
by footpad (Abbot) on Dec 12, 2001 at 22:38 UTC

    You might try PDF-Create-0.01 (alt.) or one of the other modules returned by this search (alt). There's a tutorial here. (Note that you'll want to review the tutorial's Perl code pretty carefully; it doesn't use strict, -w, or taint mode.)

    Alternatively, if you're willing to target IE, you can create a printer-friendly version of your document using:

    <link rel=alternate media=print href="printme.html">

    Here's one discussion; there are many others online. (Personally, I don't like using this because of the cross-browser problems. YMMV.)


Re: "The web is not print"
by boo_radley (Parson) on Dec 12, 2001 at 22:49 UTC
    you may be interested in the miracles of XML and XSLT. O'reilly's has excellent books on both of them, and you can get the supa-fly peacock shirt in some cases.
    Most people are familiar with an use XML as a data record format, but it can be used to create 'normal' documents, ala DocBook.
    In the XSLT book, ISBN 0596000537, the author (Hi, Doug!) presents an incredible case study called the 'toot-o-matic' which takes a source XML document and produces :
    • Hierarchical HTML forms
    • Hyperlinked PDF files in a variety of print formats
    • Prepackaged Zip archives for offline storage
    This is a heavyweight example, but the book provides excellent and thorough explanation of the XSLT syntax, and how to perform different manipulations on a single document.
Re: "The web is not print"
by Fletch (Bishop) on Dec 12, 2001 at 22:52 UTC

    You could also step back and generate something like LaTeX and then use that to generate PS or HTML output rather than trying to directly generate one version that looks good everywhere.

      I'd second this. I had some fairly nasty ASCII that I needed to process and produce "pretty" and portable output. I used Perl to read and parse the input and then wrote LaTeX as the output. I could then use this to produce PS, PDF, and even HTML output. It might be a bit of overkill for what you need but the output really does look very professional - and LaTeX will handle page numbers, section numbers, TOC, index, footnotes etc. automatically.
Re: "The web is not print"
by Rex(Wrecks) (Curate) on Dec 12, 2001 at 22:30 UTC
    I am making the assumption that you can get the data here :)

    The easiest way I know of to do this is to use the data and create a CSV document with it. This allows ANY spreadsheet app to open it and view it, and yes, even print it :)

    It also allows the flexability of being able to use StarOffice, MS Office, Corel, KDE Office or whatever other breed of Office software you want. And yes, for your less savy users, MS Office does associate the .csv extension with Excel automatically so all they have to do is download it and click on it.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: "The web is not print"
by Anonymous Monk on Dec 13, 2001 at 01:26 UTC
    Take a look at

    It's a telephone directory, written in perl, that makes PDF output by first generating XML from its data, then running that through XMLPDF, a piece of Java code that you may or may not have to pay for, depending on your circumstances.

Re: "The web is not print"
by Foo::Bar (Acolyte) on Dec 12, 2001 at 22:39 UTC
    I like the idea of using the CSV ... very portable. On the other hand, if you ae at a locaation which uses MS Office/Star Office, it might be best to try out the Spreadsheet modules. I've never worked with them but it might be just what you need.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://131316]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2023-06-10 21:41 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (39 votes). Check out past polls.