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

Hi there,

I am trying to produce a document from Perl. Now, I know I could do this in plain text but I would like to use 'pretty' fonts and be able to surround some areas with boxes, lines, etc.

I checked CPAN for some PostScript modules but found nothing which could help me draw boxes or lines. My other thought at the moment is to use a GD module and make one big image.

Anyone had experience of this type of task before, or care to offer suggestions as to how to progress?

Thanks,
fx

Replies are listed 'Best First'.
RE: Producing documents using Perl
by BigJoe (Curate) on Aug 15, 2000 at 23:29 UTC
    I would probably take a look at txt2pdf. They used perl to create a PDF file from a text file. It has the options of colors and stuff to.

    --BigJoe

    Learn patience, you must.
    Young PerlMonk, craves Not these things.
    Use the source Luke.
(jeffa) Re: Producing documents using Perl
by jeffa (Bishop) on Aug 15, 2000 at 22:10 UTC
    One approach could be to use HTML formatting. Just produce an HTML document which could then be easily converted to PostScript. Tables with borders make decent boxes and HR and FONT tags are at your disposal.

    Hope this helps, Jeff

RE: Producing documents using Perl
by gumpu (Friar) on Aug 16, 2000 at 11:33 UTC

    You could try and generate LaTeX documents. LaTeX command are all in plain ASCII, and you get nice results. I've been using it to autogenerate documentation from programs. It also has commands to make lines and boxes around text.

    Have fun, Frans.
Re: Producing documents using Perl
by ferrency (Deacon) on Aug 16, 2000 at 01:14 UTC
    I'll tell you what I would Not recommend... that would be, generating troff/groff/nroff code directly from your Perl script, and using groff to turn it into postscript. Yikes, what a PITA that was! I guess I'm just not old-school enough.

    Better would be to check out some of the many PDF modules in CPAN.

    Update: My output wasn't simple enough. It had multiple tables, with word-wrapping within a single column in the table, embedded postscript, different font sizes and styles, etc. I figured it all out and it worked in the end; but by now I'm Sure there's an easier way.

    Alan

      Bah. It's trivially easy if your output is simple enough. For plain text, just use blank lines to separate paragraphs, and put the following line at the beginning of your output:
      .LP
      
      Then, run your output through the following program: (By default, it will output PostScript in 10-point Times Roman font. Of course, fonts and sizes can also be easily changed.)
      groff -ms

      Was that so hard? But wait, there's more...

      If you're interested in putting a box around a paragraph:

      .B1 paragraph text .B2
      And in general, lines and boxes are easily created using the pic preprocessor. It's automatically invoked by providing the -p option to groff. A simple example:
      .PS box "boxed text"; arrow; circle "circled text" .PE

      Don't be afraid.

      buckaduck

Re: Producing documents using Perl
by Anonymous Monk on Aug 16, 2000 at 15:53 UTC
    You don't state your platform so ignore the bits that don't apply.

    If these are form letters then you should consider generating a data file and using a word processor to perform mail merge for you. On Windoze OLE automation could be used to achieve this with minimal intervention. In Unix land a few well place system() calls might do the trick for you.

    Alternatively, on Windoze, the entire document could be authored by OLE automation.

    If you use the txt2pdf approach outlined above, perhaps one of the Text::Template style modules could be of assistance to get the bulk of the content sorted.
Re: Producing documents using Perl
by bliz (Acolyte) on Aug 16, 2000 at 20:04 UTC
    I would recommend opening up a copy of StarOffice, and creating a TEMPLATE of what you are wanting... then export the thing to postscript (print to file). From there, you can just open the postscript document that was generated, and replace the template values you put in ther with the actual values.. now you have a dynamic template postscript file... joy.. :)
                 "thank you, drive through please..."
    
RE: Producing documents using Perl
by t0mas (Priest) on Aug 17, 2000 at 14:30 UTC
    You can use RTF::Document to create Rich Text Format documents readable by most word-processors. It's still in alpha though...
    RTF documents are easy to create "by-hand" if you would like to. You'll find some RTF specs over at The Programmer's File Format Collection (among lots of others).

    /brother t0mas
Re: Producing documents using Perl
by Anonymous Monk on Aug 16, 2000 at 20:13 UTC

    Depending on the nature and scope of the project, I have had a good deal of success using, for instance, a MySQL database, Perl, and QuarkXpress on a Mac to do business cards for a 150+ person company.

    And while this doesn't really sound like what you want, I thought I would mention it just in case as it's a poorly-documented solution of which many are completely unaware.

    Essentially you play to Perl's strengths, using it to parse the text/db output/HTML/whatever and perform basic markup functions/regexps using Quark's style-sheet markup language (see deep in the Quark Appendices). Quark allows you to import with style sheets and there is *nothing* that you would ordinarily do to text in Quark that you can't do using the markup language, and you can then add images, etc., to your final product (not a bad thing for long documentation, business cards...).

    If anyone is interested I'd be happy to explain some of the strengths and weaknesses of this approach off-list.

    Otherwise, if open/free is the criteria, LaTex is definitely worth a look.