About Print Templates
Microsoft Internet Explorer 5.5 and later allows you to customize how the WebBrowser Control and Windows Internet Explorer print and preview documents. Print templates are the mechanism for printing and previewing; they are HTML files that developers create, using the object model exposed by the print template behaviors.
With a custom print template, you can control:
- The layout, content, and handling of pages printed or previewed.
- The look, feel, and functionality of the print/preview user interface.
With such extensive layout and handling control, Internet Explorer fits new printing application scenarios, such as:
- Adding boilerplate text to print jobs, such as art, legal notices, and advertisements.
- Customizing the placement and style of page elements, such as page numbers or chapter headings.
- Complex printing, such as multi-fold brochures or book-style printing using mirrored margins.
By default, Internet Explorer uses its own print template. So, how do you get Internet Explorer or the WebBrowser Control to recognize your custom template and use it in place of the default print template?
Although print templates are HTML files, there is currently no scriptable mechanism for using print templates, nor is there any mechanism to use them in Microsoft Visual Basic. Customized print templates can be recognized and used only from C++ in an application or control that can issue or intercept the IDM_PRINT or IDM_PRINTPREVIEW command. For a description of how to use a custom print template, read the section titled "How Do I Use These Print Template Things?" in Beyond Print Preview: Print Customization for Internet Explorer 5.5.
A print template is written using standard HTML, script, and four element behaviors specific to print templates: LAYOUTRECT, DEVICERECT, TEMPLATEPRINTER, and HEADERFOOTER.
The LayoutRect and DeviceRect element behaviors provide a page's visual formatting. A DEVICERECT element represents a single page for printing. LAYOUTRECT elements go inside DEVICERECT elements and establish the area of each page containing the source document's content. Element attributes provide the specifics. The TemplatePrinter element behavior is a print template's interface to the printer and to Page Setup settings. Properties and methods provide the desired effect. The HeaderFooter behavior is a conversion tool. It takes header and footer formatting strings, typically from the Page Setup dialog box, and generates HTML that you can insert in the DEVICERECT elements of a print template.
For detailed instructions of creating a custom print template, study the section titled "Writing a Print Template" in Beyond Print Preview: Print Customization for Internet Explorer 5.5.
A print template doesn't have a default user interface; thus, your template must generate whatever user controls you want to provide. Typical controls include a button to print, a button to access page setup, and a button and/or check boxes so the user can change the view.
For detailed instructions of creating a custom print preview user interface, study the section titled "Building a Print Preview User Interface" in Print Preview 2: The Continuing Adventures of Internet Explorer 5.5 Print Customization.