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


https://www.internet.com


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

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