spacer
Yehuda Shiran September 28, 2001
Counting Pages in A Print Job
Tips: September 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


There are several ways to find out how many pages there are in a print job. We define a page by a LAYOUTRECT element within a DEVICERECT element. Here is a typical definition of Page 1, in JavaScript:

newHTML  = "<IE:DEVICERECT ID='devicerect1' MEDIA='print' CLASS='masterstyle'>";
newHTML += "<IE:LAYOUTRECT ID='layoutrect1' CONTENTSRC='document' 
  ONLAYOUTCOMPLETE='onPageComplete()' NEXTRECT='layoutrect2' CLASS='contentstyle'/>";
newHTML += "</IE:DEVICERECT>";
The first method to count pages is by simply counting the number of DEVICERECT elements:

pageTotal = document.all.tags("DEVICERECT").length
The other way is to find out the page where there was no content overflow (last page):

pageTotal = parseInt(event.srcElement.parentElement.id.substring(10), 10);
As you can see from Page 1's definition, the ONLAYOUTCOMPLETE event handler is attached to the LAYOUTRECT element. Its parent is a DEVICERECT element which has an ID of devicerecti. If we extract the substring that begins with the numeric part, we'll end up with the page number. There are 10 characters before the page number in the DEVICERECT's ID.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business