Export (0) Print
Expand All

LAYOUTRECT Element | LayoutRect Behavior

Creates a container element for document content in a print or print preview template.


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 LayoutRect object.

Attribute Property Description
BORDER border Sets or retrieves the width of the border to draw around the object.
BORDERCOLOR borderColor Sets or retrieves the border color of the object.

Retrieves the document object of the page being printed or print-previewed.


Sets or retrieves the content source for a LAYOUTRECT element in a print template.

https://msdn.microsoft.com/en-us/library/aa753298.aspx honorPageBreaks Not implemented.
https://msdn.microsoft.com/en-us/library/aa753299.aspx honorPageRules Not implemented.
MARGINHEIGHT marginHeight Sets or retrieves the top and bottom margin heights before displaying the text in a frame.
MARGINWIDTH marginWidth Sets or retrieves the left and right margin widths before displaying the text in a frame.

Sets or retrieves the identifier of the next LayoutRect element used to format the document.

Style attribute Style property Description
background-attachment backgroundAttachment Gets or sets how the background image is attached to the object within the document.
background-clip New for Windows Internet Explorer 9  backgroundClip Gets or sets the background painting area.
background-origin New for Internet Explorer 9  backgroundOrigin Gets or sets the background positioning area of a box or multiple boxes.
background-size New for Internet Explorer 9  backgroundSize Gets or sets the size of the background images.
font-stretch New for Internet Explorer 9  fontStretch Gets or sets a value that indicates a normal, condensed, or expanded face of a font family.
right right Gets or sets the position of the object relative to the right edge of the next positioned object in the document hierarchy.
-ms-zoom zoom Gets or sets the magnification scale of the object.


LAYOUTRECT elements define the area or areas (and their styles) on a page where a document's content is displayed when printed or during print preview. In a print template, LAYOUTRECT elements are contained by DEVICERECT elements, which define the printable area of the print template. A DEVICERECT can contain more than one LAYOUTRECT.

A LAYOUTRECT element is intended for use when building a print template. While this element renders on a Web page, most of its functionality is disabled when it is used outside a print template.

A print template typically has a series of connected LAYOUTRECTs into which a source document can flow as it is rendered for printing or previewing. The first LAYOUTRECT in the series defines the source of the content by specifying a contentSrc property or attribute. ContentSrc can be set to the string "document" to indicate that the current document displayed should be used as the source, or it can be set to a URL specifying another source. The LAYOUTRECT element also has a nextRect attribute or property to specify another LAYOUTRECT into which the source content should continue to flow once the current LAYOUTRECT is full. Each LAYOUTRECT in the series, except the last, defines a nextRect pointing to the next LAYOUTRECT in the series.

A print template usually handles documents of various lengths. It must provide enough LAYOUTRECT elements to accommodate an arbitrary amount of content. To accomplish this, use script to create LAYOUTRECTs dynamically, as a source document loads, by specifying an onlayoutcomplete event handler for each LAYOUTRECT. The event handler should check the event's contentOverflow property. When the contentOverflow property is true, the handler can create a new LAYOUTRECT with an id, an onlayoutcomplete handler, and a nextRect attribute pointing to the next LAYOUTRECT element in the series. The onlayoutcomplete event can fire more than once on a single LAYOUTRECT. For this reason, the event handler must cancel itself once it has been called, to prevent the handler from firing more than once.

A LAYOUTRECT element must have a style that defines a width and height; the default value for each of these properties is zero. A print template can obtain the current page setup information by querying the TemplatePrinter behavior properties, including marginBottom, marginLeft, marginRight, marginTop, pageWidth and pageHeight. A LAYOUTRECT style cannot redefine styles within the content source; for instance, it cannot redefine font-family or font-weight.

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

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

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

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

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.


Click below to download a sample application that demonstrates the print and print preview features of 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 example shows some of the basic elements of a print preview template, including the onlayoutcomplete event handler. Note that the LAYOUTRECT elements in this example define their nextRect attributes before the next LAYOUTRECT is added to the series. This template supports print preview, but not printing. For information on printing support, see the TEMPLATEPRINTER reference page.

<?import namespace="ie" implementation="#default">
<STYLE type="text/css">
    border:1 solid black;
<SCRIPT language="JScript">
index = 1;

function OnRectComplete()
    if (event.contentOverflow == true)
        document.all("LRect" + index).onlayoutcomplete = null;

        newHTML = "<IE:DEVICERECT id=page" + (index + 1) + "
        media=print class=pagestyle>";
        newHTML += "<IE:LAYOUTRECT id=LRect" + (index + 1) + "
        onlayoutcomplete='OnRectComplete()' nextRect=LRect" + (index
        + 2) + " class='layoutstyle'/>";
        newHTML += "</IE:DEVICERECT>";

        pagecontainer.insertAdjacentHTML("beforeEnd", newHTML);
<DIV id="pagecontainer">
<IE:DEVICERECT id="page1" media="print" class="pagestyle">
    <IE:LAYOUTRECT id="LRect1" contentsrc="document"
    onlayoutcomplete="OnRectComplete()" nextRect="LRect2"

See Also

Community Additions

© 2015 Microsoft