Gossamer Forum
Home : General : Perl Programming :

Content-Length Problem.

Quote Reply
Content-Length Problem.
I am facing a problem here.
I am writing a script which will produce HTML output for printing.
I want to introduce "page-break" after a specified "Content-Length" and then it continues printing the remaining input. Lets suppose after EVERY 130 characters, how can I insert <DIV style="page-break-after:always"></DIV>
and then continue printing the remaining part? I tried to use 'while' statement but could not think of any good solution. Thanks in advance for any help. Sara. ################### CODE #######################
$text = qq|
This is line no 1 and then it continues ..... and then a line break
This is line no 2 and then it continues ..... and then a line break
This is line no 3 and this is a long line and then it continues ..... and then a line break
This is line no 4 and then it continues ..... and then a line break
|;

$length = length ($text);

print qq|
<div align="center">
<center>
<table>
<tr>
<td width="500" style="text-align: Justify" valign="middle" align="right">
$text
</td>
</tr>
</table>
</center>
</div>
|;

Quote Reply
Re: [samsara] Content-Length Problem. In reply to
Its pretty easy to do it with words... but not so easy with charachters. You could try something like;

Code:
my $text = qq|
This is line no 1 and then it continues ..... and then a line break
This is line no 2 and then it continues ..... and then a line break
This is line no 3 and this is a long line and then it continues ..... and then a line break
This is line no 4 and then it continues ..... and then a line break
|;

my $text = &cut_up($text);

print "Content-type: text/html \n\n";
print "Text returned was: $text";

sub cut_up {

my $string = $_[0];
my @cut = split / /,$text;

# if the string is less than 100 words, then lets just pass it back...
if ($#cut < 100) { return $string; }

# otherwise we can start slicing, dicing, etc...
my $count = 0;
my $back;
my $put_in = q|<DIV style="page-break-after:always"></DIV>|;
foreach (@cut) {
$count++;
if ($count =~ /00$/) {
$back = "$_ $put_in ";
} else {
$back = "$_ ";
}

return $back;

}
}

I didn't try the above code.. but it *should* work. Basically it inserts the value held in $put_in every 100 words.

Enjoy =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [samsara] Content-Length Problem. In reply to
Just be sure and run the page/script through multiple browsers... the style-pagebreak used to cause problems for me. The print job would spool off into la-la land, and then my systems would hang. I believe it was IE5x on Win98, but am not sure of the exact version of IE.