|
September 28, 2001 Counting Pages in A Print Job Tips: September 2001
Yehuda Shiran, Ph.D.
|
|
|
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: