The following is my patent-pending method for generating documents automatically using Perl:

  1. Start OpenOffice.org, go into the options (under the Tools menu) and under Load/Save, click on General. Turn off the option "Size optimization for XML format (no pretty printing)". (This will make a later step much easier.)
  2. Use OpenOffice.org Writer to create a sample document with all of the formatting and setup exactly the way you want (tables, columns, image placement, fonts, and so forth), but sample/dummy content (e.g., a thank-you to Jane Doe for the wonderful Widget Set). Save this.
  3. Unzip it into a working directory.
  4. Copy and paste the contents of content.xml into a big string in your Perl script. Use an editor macro to backslash all the double quotes in it so that it's one big string. (Update: Or you can use a heredoc as PodMaster suggests.)
  5. Interpolate your content. You can do this in a loop or whatever. (I often do tables out of a database, so I do the old ".(join"\n",map{tablerow($_)}@rows)." trick, but for what you're doing simple interpolation will probably be fine.) Note that certain characters (notably ampersand) have to be written as entities, so any that you're going to have to deal with be sure to include in your sample document so you can see the encoded form.
  6. open XML, ">$workdir/content.xml"; print XML $interpolatedcontent; close XML;
  7. Zip up the contents of your working directory into an sxw. You can either use Archive::Zip or just backtick out to info-zip or whatever zip app you use.
  8. Doubleclick the sxw and print it. I haven't found a way to automate this step yet. However, while I haven't done this, it would easily be possible to generate multiple items (in a loop) in one document separated by hard page breaks and print them all at one go. If you want to take this approach, be sure to put a hard page break in your sample doc so you have one to copy-and-paste into your string.

$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

In reply to Re: automatic thank you! by jonadab
in thread automatic thank you! by csuhockey3

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.