spacer

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

home / experts / javascript / column93


Print Templates, Part IV: User's Settings

Technical Lead
Thomson Reuters (Markets) LLC
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?


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.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


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