spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column93


Print Templates, Part IV: User's Settings

Product Designer
Aquent
US-WA-Redmond

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

Assembling the Pages

The functions addFirstPage() and addNextPage() assemble the pages. Each page consists of a LAYOUTRECT element within a DEVICERECT element. Here is the first page definition:


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 LAYOUTRECT element ID is a concatenation between the string "layoutrect" and the page number (1). The CONTENTSRC attribute specifies the formatted document. The value "document" means the current document. The LAYOUTRECT element points to the next page's LAYOUTRECT element ID (layoutrect2). The CLASS definitions ensure the page will be formatted according to the STYLE rules contentstyle and masterstyle.

After defining the first page's HTML, we insert it in the page:

pagecontainer.insertAdjacentHTML("afterBegin", newHTML);

The textHead and textFoot properties get the instructions as to how to assemble the header and the footer, as they are defined by the user in the Page Setup dialog box:

myheaderfooter.textHead = printer.header;
myheaderfooter.textFoot = printer.footer;

The headerFooter's URL and title properties are extracted from the current document object. The object is passed in dialogArguments._IE_BrowseDocument:

myheaderfooter.url = dialogArguments.__IE_BrowseDocument.URL;
myheaderfooter.title = dialogArguments.__IE_BrowseDocument.title;

Finally, we set the templatePrinter's page number:

myheaderfooter.page = 1;

and we add the header and the footer:

addHeaderAndFooterToPage(1);

The function addNewPage() is very similar. It assembles a LAYOUTRECT element within a DEVICERECT element. The ID entries are created from the current page number, lastPage. Here is addNewPage():

function addNewPage() {
  document.all("layoutrect" + lastPage).onlayoutcomplete = null;
  myheaderfooter.page = lastPage + 1;

  newHTML  = "<IE:DEVICERECT ID='devicerect" + (lastPage + 1) +
    "' MEDIA='print' CLASS='masterstyle'>";
  newHTML += "<IE:LAYOUTRECT ID='layoutrect" + (lastPage + 1) +
    "' ONLAYOUTCOMPLETE='onPageComplete()' NEXTRECT='layoutrect" +
    (lastPage + 2) + "'  CLASS='contentstyle'/>";
  newHTML += "</IE:DEVICERECT>";

  pagecontainer.insertAdjacentHTML("beforeEnd", newHTML);
  addHeaderAndFooterToPage(lastPage + 1);
  lastPage++;
}

Next: How to print the pages


http://www.internet.com

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 >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: September 24, 2001
Revised: September 24, 2001

URL: http://www.webreference.com/js/column93/5.html