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

Yehuda Shiran, Ph.D.
Doc JavaScript

UNIX Administrator - Linux/Solaris (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume
Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

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.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Administering MySQL Databases on the Web Using PHP · Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
So what is an Oracle Nested Table? · E-Discovery Architectures 101 · eBay Embraces Big Sellers, Cyber Monday Trends