PrintHTML

Description

Prints either specified HTML text or the HTML document specified by the URL using the current printing settings in the same session context. The method is asynchronous. It returns before the document is downloaded and printed.

Important note:

The html to be printed must not be 'ScriptX-enabled' - it must not contain an object tag referencing the ScriptX object nor script code that uses that object. Attempting to print html (either specified html text or document specified by url) that contains the ScriptX object can lead to strange errors and failure of the entire printing process, including causing Internet Explorer to stop responding.

PrintHTML may be used to organize a printing queue in a separate process, in which case the current window may be closed without waiting for pending downloads to complete. See OwnQueue for more details.

Syntax

printing.PrintHTML(url[, prompt = false])

Parameter Description
url (String) URL/html text to print:
ProtocolPrints
html:// The html is loaded and printed, e.g. html://<html><head><title>Dynamic Printing</title></head><body>Hello world!</body></html>
any other, e.g. http://, https:// or if no protocol specified. The document is downloaded and printed. A relative (to the current page) url may be given.
Note: The target document at 'url' must NOT be 'ScriptX-enabled'.
prompt (Bool) Specifies whether or not the user should be prompted before the download is queued

Return Value

Returns false if printing with a prompt and the user cancels the printing.

Applies To

printing

Examples

Check out the source code of the ScriptX Advanced Printing and ScriptX Techie Printing  examples.

The following simple but complete example shows how to print an externally-located document:

<body>

<!-- MeadCo Security Manager - using evaluation license -->
<object viewastext style="display:none"
classid="clsid:5445be81-b796-11d2-b931-002018654e2e"
codebase="smsx.cab#Version=8,0,0,56
">
  <param name="GUID" value="{C4DB5D29-BE52-46B9-9DDF-46A167170F81}
">
  <param name="Path" value="sxlic.mlf">
  <param name="Revision" value="0">
</object>

<!-- MeadCo ScriptX -->
<object id="factory" viewastext style="display:none"
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814">
</object>

<script defer>
function window.onload() {
  idPrint.disabled = false;
}

function PrintHTML(url) {
  factory.printing.PrintHTML(url);
}
</script>

<input id=idPrint disabled type="button" value="PrintHTML('info.htm')"
 onclick="PrintHTML('info.htm')">

</body>

The following example illustrates dynamic creation of the HTML to be printed:

 <!-- MeadCo Security Manager - using evaluation license -->
<object viewastext style="display:none"
classid="clsid:5445be81-b796-11d2-b931-002018654e2e"
codebase="smsx.cab#Version=8,0,0,56
">
  <param name="GUID" value="{C4DB5D29-BE52-46B9-9DDF-46A167170F81}
">
  <param name="Path" value="sxlic.mlf">
  <param name="Revision" value="0">
</object>

<!-- MeadCo ScriptX -->
<object id="factory" viewastext style="display:none"
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814">
</object>

<script>
function doPrintDemo() {

    var n;
    var str = "<html><head>";
    str += "<link rel='stylesheet' type='text/css' href='/zeepe/resources/zp_content.css' />";
    str += "<title>ScriptX Dynamic Reports</title></head><body>";

    for (n=0; n<10; n++) {
        str += "<p>Dynamically created line number: " + (n+1) + "</p>";
    }

    str += "<hr/><p>Note that style sheets, scripts, images etc must be referenced by their full url</p>");
    str += "</body></html>";

    factory.printing.header = "ScriptX Dynamic Printing";
    factory.printing.footer = "";
    factory.printing.printHTML("html://"+str);
}
</script>

See Also

PrintHTMLEx

bottomMargin, collate, copiesduplex, footer, headerleftMarginonafterprintonuserprint, paperSize, paperSourceportrait, printBackground, printerprintToFileName, rightMargintemplateURL, topMargin

BatchPrintPDFIsSpoolingOwnQueue, PageSetupPrint,  PrintSetupPrintXML,  WaitForSpoolingComplete