Print Templates, Part IV: User's Settings: Assembling the Pages - Doc JavaScript | WebReference

Print Templates, Part IV: User's Settings: Assembling the Pages - Doc JavaScript

Print Templates, Part IV: User's Settings

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'

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: = 1;

and we add the header and the footer:


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; = 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);

Next: How to print the pages

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