Print Templates, Part IV: User's Settings: Template6's Flow - Doc JavaScript | WebReference

Print Templates, Part IV: User's Settings: Template6's Flow - Doc JavaScript


Print Templates, Part IV: User's Settings

Template6's Flow

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. This is what the application looks like. The template we explain in this column is template6.html. Download it to your drive from column93.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 (no need to hit Return at the end). Click the Print Preview button to see the effect of the template.

The print template template6.html's algorithm is similar to other templates previously presented in this series. The HTML portion of the page is very minimal, mainly for the positioning of two XML behaviors, templatePrinter and headerFooter, and for the placement of a DIV element that stores the pages that are built on line. Here is the HTML section:

<BODY ONLOAD="init()">
<IE:TEMPLATEPRINTER ID="printer"/>
<IE:HEADERFOOTER ID="myheaderfooter"/>
<DIV ID="pagecontainer">
<!-- Dynamically created pages go here. -->
</DIV>
</BODY>

The init() function starts the template's algorithm. First, it sets the pages' style attributes according to the user's entries in the Print Setup dialog box. The function init() also calls addFirstPage(). The first page is the easiest page to install, as you can set its ID. The function addFirstPage() installs the DEVICERECT and LAYOUTRECT elements of the first page, as well as its header and footer through the addHeaderAndFooterToPage() function. The LAYOUTRECT element of the first page includes the onPageComplete() event handler. This event handler makes sure the rest of the pages are being generated, via the addNewPage() function. It works similarly to addFirstPage(), except that the page ID needs to be computed on the fly.

The event handler onPageComplete() detects when all pages are done and goes on to print them. The function checkIfPrintRequested() checks the button pressed in the Microsoft print application window: Print Preview, Print with Prompt, or Print w/o Prompt. The function calls the Print Setup dialog box if Print with Prompt is pressed. If Print is requested, it calls the function printPrep(), which in turn call printNow(). This function does the actual printing, after checking that the user-specified first and last pages are consistent with each other and with the actual length of the document.

Next: How to convert style definitions to objects

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/2.html