Print Templates, Part III: HeaderFooter: Adding a HeaderFooter Element - Doc JavaScript | WebReference

Print Templates, Part III: HeaderFooter: Adding a HeaderFooter Element - Doc JavaScript


Print Templates, Part III: HeaderFooter

Adding a HeaderFooter Element

You can call print templates only from C++. Luckily enough, Microsoft prepared a versatile application to which you can specify your own print template and your own page to view and print. To use this application, you need to have it installed. Please save it to one of your hard drives, and then click it twice. See what the application looks like. The first template we explain in this column is template4.html. Download it to your drive from Column92.zip or copy and paste it from Page 7. Once it is on your hard drive, enter its full path name in the Template Source field. Click the Print Preview button to see the effect of the template.

We base our demonstration of the HeaderFooter behavior on the dynamic print template we showed in Column 89. There, we called onPageComplete() whenever a page is completed, in order to start populating the next page in line. Please study Column 89. It will give you a good background to this column.

The first header and footer positioning algorithm we present here is quite simple. We first render all pages, and only then add headers and footers to all pages. We distinguish in onPageComplete() between the case of overflow when a new page should be assembled, and the case when there is no overflow, which means it is the last page:

if (event.contentOverflow == true) {
    addNewPage();
  }
  else if (headersFootersAdded == false) {...

We also set the headersFootersAdded variable to avoid duplicates of headers and footers.

To add headers and footers to a print template, you need to include the HeaderFooter behavior. Put it somewhere in the BODY section of the page:

<IE:HEADERFOOTER ID="myheaderfooter"/>

Notice the XML namespace IE. You need to import it in the HEAD section:

<?IMPORT NAMESPACE="IE" IMPLEMENTATION="#default">

Next: How to add headers and footers after rendering

https://www.internet.com


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

URL: https://www.webreference.com/js/column92/2.html