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

Yehuda Shiran, Ph.D.
Doc JavaScript

Data Center Architect
The Computer Merchant, Ltd
US-MA-chelsea

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint