TEMPLATEPRINTER Element | TemplatePrinter Behavior

Provides a print template with access to page setup and printer settings and control over print jobs initiated from the template.

Syntax

XML <TEMPLATEPRINTER ID=sID />
HTML N/A
Scripting N/A

Possible Values

sID String that specifies a unique identifier for the object.

Members Table

The following table lists the members exposed by the TemplatePrinter object.

Attributes/Properties
Attribute Property Description
ALLLINKEDDOCUMENTS allLinkedDocuments

Sets or retrieves whether all documents linked to in the current document are printed with the current print job.

COLLATE collate

Sets or retrieves whether the pages of a document are collated when printed.

COPIES copies

Sets or retrieves how many copies of the document to print.

currentPage

Sets or retrieves a Boolean value indicating whether the print current page option is checked.

currentPageAvail

Sets or retrieves a Boolean value indicating whether the print current page option should be enabled in the print dialog box.

duplex

Retrieves a Boolean value indicating whether double-sided printing is active.

FOOTER footer

Sets or retrieves the footer formatting string from the Page Setup dialog box.

FRAMEACTIVE frameActive

Sets or retrieves a value that indicates whether the option button labeled Only the selected frame in the Print frames section of the Print dialog box is selected.

frameActiveEnabled

Enables or disables the radio button labeled Only the selected frame in the Print frames section of the Print dialog box.

FRAMEASSHOWN frameAsShown

Sets or retrieves whether the document's frames are printed exactly as they appear on the screen.

FRAMESETDOCUMENT framesetDocument

Sets or retrieves whether all the documents in the frameset are printed.

HEADER header

Sets or retrieves the header formatting string from the Page Setup dialog box.

headerFooterFont

Sets or retrieves a combination of strings that define font properties of the header and footer.

MARGINBOTTOM marginBottom

Sets or retrieves the bottom margin of the document to be printed.

MARGINLEFT marginLeft

Sets or retrieves the left margin of the document to be printed.

Sets or retrieves the left margin of the document to be printed.
MARGINRIGHT marginRight

Sets or retrieves the right margin of the document to be printed.

MARGINTOP marginTop

Sets or retrieves the top margin of the document to be printed.

orientation

Sets or retrieves the printing orientation for the current printer.

PAGEFROM pageFrom

Sets or retrieves the first page in the document to be printed.

PAGEHEIGHT pageHeight

Retrieves the current height of a page on the printer.

PAGETO pageTo

Sets or retrieves the last page in the document to be printed.

PAGEWIDTH pageWidth

Retrieves the current width of a page on the printer.

Retrieves the current width of a page on the printer.
SELECTEDPAGES selectedPages

Sets or retrieves whether a selected range of pages is printed, rather than the whole document.

SELECTION selection

Sets or retrieves whether the selected portion of the document is the only part to be printed.

selectionEnabled

Enables or disables the Selection radio button on the Print dialog box.

TABLEOFLINKS tableOfLinks

Sets or retrieves whether to print a table of links as part of the current print job.

unprintableBottom

Retrieves the size of the bottom unprintable margin for the current printer.

unprintableLeft

Retrieves the size of the left unprintable margin for the current printer.

unprintableRight

Retrieves the size of the right unprintable margin for the current printer.

unprintableTop

Retrieves the size of the top unprintable margin for the current printer.

usePrinterCopyCollate

Sets or retrieves a value that indicates whether the printer copy/collate feature is enabled.

Methods
Method Description
deviceSupports

Checks whether the printer supports a specified feature.

ensurePrintDialogDefaults Not supported.
getPageMarginBottom

Returns size of bottom margin from a specified @page rule and page dimensions.

getPageMarginBottomImportant

Retrieves whether the bottom margin of the specified @page rule is marked as !important.

getPageMarginLeft

Returns size of left margin from a specified @page rule and page dimensions.

getPageMarginLeftImportant

Retrieves whether the left margin of the specified @page rule is marked as !important.

getPageMarginRight

Returns size of right margin from a specified @page rule and page dimensions.

getPageMarginRightImportant

Retrieves whether the right margin of the specified @page rule is marked as !important.

getPageMarginTop

Returns size of top margin from a specified @page rule and page dimensions.

Returns size of top margin from a specified @page rule and page dimensions.
getPageMarginTopImportant

Retrieves whether the top margin of the specified @page rule is marked as !important.

printBlankPage

Prints a blank page.

printNonNative

Sends a non-HTML document, such as a Microsoft Word document, to the printer.

printNonNativeFrames

Sends a non-HTML document, such as a Word document, to the printer from a page containing frames.

printPage

Sends a page, as defined by a DeviceRect, to the printer.

showPageSetupDialog

Displays the Page Setup dialog box.

showPrintDialog

Displays the Print dialog box.

startDoc

Uses the current print template to start a print job.

stopDoc

Ends the current print job.

updatePageStatus

Indicates the status of a print job.

Remarks

The methods of TEMPLATEPRINTER give a print template control over the start and end of print jobs ( startDoc and stopDoc), control over the printing of each individual page in a print job ( printPage), and control over the display of printing dialog boxes ( showPageSetupDialog and showPrintDialog). The properties of TEMPLATEPRINTER enable a print template to set or retrieve the page setup settings and current print job settings. For instance, a print template might set or retrieve pageWidth and pageHeight for page setup, or pageTo and pageFrom to determine the page range to print.

A TEMPLATEPRINTER element is intended for use when building a print template. Its functionality is disabled when it is used outside a print template.

This element must occur once and only once in a print template if the template is to support printing.

For security reasons, the TEMPLATEPRINTER element is enabled only when embedded in a print template; otherwise, this element is disabled. For more information, please review Safety Considerations When Using Print Templates.

When using the TEMPLATEPRINTER element, you must prefix it with an XML namespace. Declare the namespace by using the IMPORT processing instruction. For example, the namespace "IE" can be declared using the following statement:


<?import implementation="#default" namespace="IE">

The TEMPLATEPRINTER element syntax to use with this namespace is <IE:TEMPLATEPRINTER ... />.

The TEMPLATEPRINTER element is an unscoped element; that is, it does not have a closing tag. It must have a forward slash (/) before its closing bracket.

In some cases—usually when the print or print preview dialog box is displayed—the content source document has time to load before printing starts. In other cases, usually when there is no user prompt prior to printing, a print template must be designed to wait for the document to load before beginning a print job. Accomplish this by setting an onreadystatechange event handler on the contentDocument that checks the document's readyState property to see when it equals "complete." This handler is not always necessary, so a template should only set it when the property is not "complete" at the start of a print job.

security note Security Alert  Writing an Microsoft ActiveX control, binary behavior, or other binary object for use on a Web page that can load an unspecified print template can compromise the security of your application. Such a control could be appropriated to load insecure or malicious print templates. Write your control to load only specific, pre-defined templates. For more information, please review Safety Considerations When Using Print Templates and Designing Secure ActiveX Controls.

Examples

Click below to download a sample application that demonstrates the print and print preview features of Windows Internet Explorer. The application includes eight templates that increase in complexity from minimal functionality to those that include user interface elements. You can also use the application to test templates of your own design. You must download the sample application to your own computer to run it.

Download Print and Preview Template Test Application

The following script block and the opening lines of the BODY element are taken from a print template. They show the minimum features necessary to provide printing support in a print template. The Init function is an event handler attached to the print template's body element for the onload event. "Layout1" is the id for the first LAYOUTRECT of the print template. "PageX," where X is a positive integer, is the id format for the DEVICERECTs in the print template.


<SCRIPT language="JScript">
<?import implementation="#default" namespace="IE">
function Init()
{
    switch (dialogArguments.__IE_PrintType)
    {
        case "Prompt":
            if (Printer.showPrintDialog()) 
                DoPrint();
            break;
        case "NoPrompt":
            DoPrint();
            break;
        case "Preview":
        default:
            break;
    }
}

function DoPrint()
{
    if (Layout1.contentDocument.readyState == "complete")
    {
        // This block is called when printing with user prompt
        // because the Print and Preview dialog boxes give time for
        // the content document to complete loading
        PrintNow();
    }
    else
    {
        // This block is usually called when printing without a user prompt.
        // It sets an event handler that listens for the loading of the content
        // document before printing. Sometimes, however, even without a user prompt,
        // the content document is loaded in time for the previous
        // block to execute.
        Layout1.contentDocument.onreadystatechange = PrintWhenContentDocComplete;
    }
}

function PrintWhenContentDocComplete()
{
    if (Layout1.contentDocument.readyState == "complete")
    {
        Layout1.contentDocument.onreadystatechange = null;
        PrintNow();
    }
}

function PrintNow()
{
    firstPage = Printer.pageFrom;
    lastPage = Printer.pageTo;
    
    Printer.startDoc("A print job");
    
    for (i = firstPage; i <= lastPage; i++)
    {
        if (document.all("Page" + i))
            Printer.printPage("Page" + i);
        else
            alert("Print Error");
    }
            
    Printer.stopDoc();
}
</SCRIPT>
</HEAD>

<BODY onload="Init()">
<IE:TEMPLATEPRINTER id="Printer"/>
.
.
.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft