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

As part of a CGI script that I am writing, I recieve input from textareas. The textareas might be from a few lines long to about 20 lines long. When the script recieves the input, I would like each one to be buffered to a certain amount of characters (probably about 5000), so when the output (in html) is printed (as in from a printer), each textarea is on a new page.

On a side note, if anyone knows how to break html into separate printable pages, that would be even more helpful.

Thanks.
  • Comment on Is there any easy way to buffer a string?

Replies are listed 'Best First'.
Re: Is there any easy way to buffer a string?
by premchai21 (Curate) on Aug 22, 2001 at 21:28 UTC

    'Buffer'? You mean pad with trailing blanks? See length, substr, perlop (the . and x operators). But I don't think that's going to help. Padding isn't going to be reliable here, because think of the different page sizes, fonts and font sizes. Not only that, but extra blank spaces get ignored in HTML. Perhaps you could try splitting it into several individual HTML documents. Or you could output PostScript or PDF or some other format which supports such instructions instead; there are modules on CPAN that will let you do this. I think when printing plain text that the ^L character (expressed as \cL in Perl) produces a form feed, which feeds the printer to the next page. I'm not sure all printers do that, though.

    HTH.

Re: Is there any easy way to buffer a string?
by dga (Hermit) on Aug 22, 2001 at 21:22 UTC

    Getting web browswers to cooperate in layout especially to printers is problematic. If you get one working the others will not work. You may need to go to another format like postscript or pdf so that you get control over the page layout on printing.

    As for buffering the string, perl will automatically allocate enough space to hold the string. If you mean truncating the string to a certain maximum length you can use html attributes on the textarea to limit the size that way (these of course can be worked around by a user) and/or use substr() to trim the end off at the desired length.

    Update: Padding the value can be accomplished with sprintf (or printf) with a "%-4000s" format specifier which will add a lot of blank space after the string which will make your page load more slowly. Also notes the span deal in css and makes note to self to try that out.

      No, I mean how do I inflate a string of about 2000-3000 characters to about 4000 characters, with the extra characters being whitespace.
Re: Is there any easy way to buffer a string?
by jryan (Vicar) on Aug 22, 2001 at 22:35 UTC
    I think I found myself an answer...

    Here is a css property that does what I want, in case anyone else is interested.

    <style> span { page-break-after: always } </style>

    From now on, whenever the browser encounteres a <span> tag, it will insert a page break when printing.

      Set this on a specific span id, or you could end up with very funny prints:
      <style> span.printhere { page-break-after: always } </style> example <textarea>balblalblalbla</tesxtare><span id="printhere"></span>


      T I M T O W T D I