http://www.perlmonks.org?node_id=630512

Ben Win Lue has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed brethren,

i have to create good looking paper by printing the data in my database! I need to display headlines, texts and tables.
How am I going to do this?

My first idea was to generate a pdf and print this.
Is there an easier way?
What module is the best for creating such a pdf?

Thanks in advance

Replies are listed 'Best First'.
Re: Producing Nice Prints
by almut (Canon) on Aug 03, 2007 at 14:12 UTC

    There are of course many ways to print stuff, but I would go the PDF route. This has the added benefit, that you can easily view the documents online, in addition to getting nice looking printouts.

    Other options would for example be to use TeX, or to generate PostScript directly, but unless you like things with a somewhat higher geek factor, generating PDF using one the CPAN modules will probably be easier... :)

    For creating PDF from Perl I personally like PDF::API2, but there are other modules, too...

    Update: Maybe you could tell a bit more about what features you need, in particular whether you want automatic layout of tables, paragraph wrapping, etc.  The above mentioned approach using PDF:API2 is rather low-level, i.e. you'd essentially have to make most layouting decisions yourself, like what column widths to use, how long a line of text can be to fit in the available space, and so on.

    For many purposes this is okay, but if you're thinking of something more high-level, using a proper batch typesetting system would be the way to go. On the Perl side, this would involve writing out the desired content plus the proper markup. As there are many sophisticated templating systems for Perl, it is of course well-suited for this task.   I already mentioned TeX (typically used in combination with the macro package LaTeX). It is one of the oldest and probably the most well-known tool for the purpose (there also is a variant which directly generates PDF output). A more exotic, less well-known batch typesetter is Lout1 (which I was a big fan of some time ago, when I had to produce more documents than I have to now). Most of these approaches have a rather steep learning curve, though, but once you get the hang of it, those tools may help a lot to produce professionally looking output. Or, put differently, it's a matter of saving time now vs. saving time later. :)

    BTW, my personal experience with creating nice looking printouts from HTML is, that it soon becomes quite a PITA, for anything non-trivial... (current browsers just aren't ready for prime time in this regard, IMHO) — but YMMV, and it ultimately depends on how 'nice' your printouts are supposed to be.

    ___

    1  just in case anyone is interested... and 'cos it's somewhat hard to find: current version 3.36, also see here.

Re: Producing Nice Prints
by swampyankee (Parson) on Aug 03, 2007 at 14:32 UTC
    My first idea was to generate a pdf and print this.

    Did you look into anything else? Plain text? HTML? Excel? or another spreadheet?

    Is there an easier way?

    Always ;-)

    You will need to be a trifle more forthcoming with information. Some databases, e.g., Oracle, have report-generating features. These may be adequate. What operating system? Is the output of a plain text file adequate? If so, format may be adequate.

    There are several modules for creating PDF (see PDF); I'd tend to use PDF::API2 or PDF::CreateSimple.

    However, my preference would be to generate HTML. This is for a couple of reasons, one is that if this is only going to be done once or twice, it may be easier to fix minor errors by directly editing the HTML, instead of editing the program, re-running the report generation, etc.


    emc

    Information about American English usage here and here.

    Any New York City or Connecticut area jobs? I'm currently unemployed.

      I'll also mention Excel ... the advantages are that:

    • There's a good package on CPAN to create the spreadsheets that gives you an easy way to do your headings & such.
    • A spreadsheet is more flexible than a PDF--the users may reuse the data, or extend the spreadsheet if needed.
    • ...roboticus

Re: Producing Nice Prints
by CountZero (Bishop) on Aug 03, 2007 at 14:54 UTC
    I can only give advice based upon my own experience.

    Using the various PDF-modules on CPAN is far from easy. Not only is the API rather complicated, there are almost no simple higher level routines to --for instance-- print a whole paragraph, nicely formatted, or even to add a paragraph to a page with automatic page-breaks and page numbering and the like.

    That being said, there are a few modules which have a very specific functionality, such as PDF::ReportWriter which makes so-called business-reports, which are perhaps exactly what you are looking for. I used this module some-time ago, but as I needed additional functionality, I abandoned it and now write my reports on basis of Template::Toolkit-templates which output LaTex files rendered into PDF. It is totally flexible but it requires you to learn both the Template Toolkit language as well as LaTex!

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Producing Nice Prints
by marto (Cardinal) on Aug 03, 2007 at 14:07 UTC
    You may be interested in PDF::Template if you want to go down the PDF route. It looks pretty interesting though I have not used it myself.

    Cheers

    Martin
Re: Producing Nice Prints
by moklevat (Priest) on Aug 03, 2007 at 15:25 UTC
    Based on your need to display "headlines, texts, and tables", you might consider Perl6::Form.
Re: Producing Nice Prints
by apl (Monsignor) on Aug 04, 2007 at 13:11 UTC
    If you consider an alternate route, consider the Perl format construct.