...

View Full Version : script for calculating # of lines used on a page



canadianjameson
08-03-2004, 10:51 PM
i need to design a script to calculate the number of lines of a page that have been used. based on the result i want to be able to activate or not activate certain features.

what i've come up with so far is this:
to not lose any data on a printout of 8.5x11 inch letter size paper, you need:
width = 536 pixels
639 pixels high
(or 216 x 279 mm)
according to http://dsv.su.se/jpalme/web-ruler.html

how can i use this to calculate how far down i am with regards to nearing the end of a printable page?

Willy Duitt
08-04-2004, 03:06 AM
Here is the routine I use in my editor to line number when debugging scripts. It may help in answering your question on line numbers but I forsee a fatal flaw in your logic that line numbers will help you in determining where to break a page for printing...

The flaw being...
You will also need to find the line height in order to make a make a more accurate guesstimate....

Anyways....


<script type="text/javascript">
function lineNumber(form){
input = form.text.value;
input = input.replace(/\n\r/g, '\r');
input = input.replace(/\r\n/g, '\r');
input = input.replace(/\n/g, '\r');
line = input.split('\r');

for(var i=0; i<line.length; i++){
line[i] = (i*1+1)+': '+line[i];
} form.text.value = line.join('\r');
}
</script>
</head>
<body>

<form>
<textarea cols="90" rows="25" name="text"></textarea>
<br /><br />
<input type="button" value="Line Number" onclick="lineNumber(this.form);" />
</form>


.....Willy

canadianjameson
08-04-2004, 05:37 PM
hehe, always on the ball. I realised the flaw aswell, which was going to be my next question.

assuming that all the font sizes were the same (say... font size = 2), could this be programmed into the script?

in retrospect i suppose i'm complicating things. basically what i'm trying to do is as follows:

if the printed page height and width are as follows:
height = 639 pixels
width = 536 pixels

i'd like to be able to say:


if ( height > 600 px )
{
class(static-box)= visibility: hide;
}


the reason for this is because i have a CSS class that displays "company info" on the bottom of a form success page so that when the people print out the page, it has the added info on the bottom of the page. as seen here



head:
<style type="text/css" media="print">
{
.notPrinted { display: none; }
.static-box { display: block; }
}
</style>

<style type="text/css" media="screen, projection">
.static-box,
</style>

....
bottom of body:

<table border="0" align="center">
<tr>
<td align="center" style="position:absolute; bottom: 0px; page-break-after:always;" class="static-box"><div align="center"><font size="-1">Enviromark Inc.<br />
www.enviromark.ca</font> </div></td>
</tr>
</table>


the problem is as follows... if the user fills out a ton of info in the textarea, then this little table above displays ON TOP OF the text in the textare output.

i need the if statement above to basically say "if the page is used beyond 600px, do not print this table above, because it'll print on top of the text.

heh, i hope i explained it well / concisely :)

oh, P.S: should i move the style="position:absolute; bottom: 0px; page-break-after:always;" class="static-box" line to the <table> header? would it facilitate things?

canadianjameson
08-06-2004, 04:58 AM
nothing, anyone?

canadianjameson
08-11-2004, 04:52 PM
can anyone help me here?

all i need to do i get a little script to read the height in px that would be displayed on the screen, and do an if statement based on that...

jbot
08-11-2004, 05:03 PM
FYI: there's some good JS tutorials on printable pages at DocJS (http://www.docjs.com).

hope that helps a little :)

canadianjameson
08-11-2004, 08:55 PM
that'd be great... however i cant seem to find anything on printing. any chance you could paste a direct url?

glenngv
08-12-2004, 04:34 AM
Put the content in a div then get its offset height.


<div id="content">
content here
</div>
...
if (document.getElementById('content').offsetHeight > 600)
{
//hide footer
}

And you don't need to put the footer in a table. Just put it in a div tag.

<style type="text/css" media="screen, projection">
.static-box {
position:absolute;
bottom: 0px;
page-break-after:always;
text-align:center;
font-size:1px;
}
</style>
...
<div class="static-box">Enviromark Inc.<br />www.enviromark.ca</div>

jbot
08-12-2004, 09:49 AM
mr jamieson:

>> Page Breaks in Printing (http://www.webreference.com/js/tips/000201.html)
>> Pixels to Inches Conversion (http://www.webreference.com/js/tips/011016.html)
>> Counting Pages in A Print Job (http://www.webreference.com/js/tips/010928.html)
>> Converting Dimensions for Printing (http://www.webreference.com/js/tips/010925.html)

these may not be wot you need or want, but they're worth a wee browse as is the rest of the site. :)

canadianjameson
08-12-2004, 02:22 PM
good stuff, thx



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum