Partager via


getHtmlPrintDocumentSource method

Returns the source content that is to be printed.

Internet Explorer 10

 

Syntax

var retval = MSApp.getHtmlPrintDocumentSource(htmlDoc);

Parameters

  • htmlDoc [in]
    Type: document

    The HTML document to be printed. This can be the root document, the document in an IFrame, a document fragment, or a SVG document. Be aware that htmlDoc must be a document, not an element.

Return value

Type: varies

In Windows 8, this method returns an object of type IPrintDocumentSource. Starting in Windows 8.1, the HtmlPrintDocumentSource object is returned instead, which allows you to specify print options such as margins, shrink-to-fit or page scaling, and the enabling or disabling of headers and footers.

Remarks

The following code demonstrates the use of this method to set the source for a print task.

printManager.addEventListener("printtaskrequested", onPrintTaskRequested);

/// Print event handler for printing via the PrintManager API.
function onPrintTaskRequested(printEvent) {
    var printTask = printEvent.request.createPrintTask("Print Sample",
        function (args) {
            args.setSource(MSApp.getHtmlPrintDocumentSource(document));

            // Register the handler for print task completion event
            printTask.oncompleted = onPrintTaskCompleted;
    });
}

Starting with Windows 8.1, this method returns a HtmlPrintDocumentSource object, which provides print customizations such as the ones in the following example.

printManager.addEventListener("printtaskrequested", onPrintTaskRequested);

function onPrintTaskRequested(printEvent) {
    var printTask = printEvent.request.createPrintTask("Print Sample",
        function (args) {
            // Get the print document source
            var src = MSApp.getHtmlPrintDocumentSource(document);

            // Set margins
            src.leftMargin = src.rightMargin = 96; // 1"
            src.topMargin = src.bottomMargin = 48; // 0.5"

            // Hide header and footer
            src.enableHeaderFooter = false;

            // Set print scale to 90%
            src.shrinkToFit = false;
            src.percentScale = 90; // 90%

            args.setSource(src);

            // Register the handler for print task completion event
            printTask.oncompleted = onPrintTaskCompleted;
        }
    );
}

See also

MSApp