Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts

    script for calculating # of lines used on a page

    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?
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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....
    Code:
    <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

  • #3
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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:
    Code:
    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

    Code:
    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?
    Last edited by canadianjameson; 08-04-2004 at 05:40 PM.
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #4
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    nothing, anyone?
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #5
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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...
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    FYI: there's some good JS tutorials on printable pages at DocJS.

    hope that helps a little

  • #7
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    that'd be great... however i cant seem to find anything on printing. any chance you could paste a direct url?
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Put the content in a div then get its offset height.
    Code:
    <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>

  • #9
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mr jamieson:

    >> Page Breaks in Printing
    >> Pixels to Inches Conversion
    >> Counting Pages in A Print Job
    >> Converting Dimensions for Printing

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

  • #10
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    good stuff, thx
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •