The PrintHtml(sUrl) function is not widely used but has some nice uses. It is mostly used on server side usage of ScriptX where ScriptX is used by a custom service to do printing or a web server service such as IIS.
[Update: according to the department that should know: "It's popular as hell client-side and is used by *squillions* of licensees, usually to create selectable queues of reference docs to print out that don't have to be rendered when you're on some site or other." - just goes to prove the point that it has some nice uses
.]
But, it is also useful in web applications hosted in IE (or for preference Zeepe) or in any sort of rich client application - the application does not have to be hosting the web browser control, it just has to be able to create the MeadCo ScriptX COM component and call the required properties and methods.
The nice thing about PrintHtml() is you can use it to provide really rich reports/output from information gathered from the user and you can do this in one of two ways:
- Create a rich html 'document' on the fly and print it, or
- Call a 'web service' (one based on REST, not SOAP) that returns the html document to be printed.
PrintHtml is a method that requires a license, applying a license is covered here.
On the fly
To create html on the fly, simply build the complete html as a string (it should be welformed, but given the flexibility of the Windows Web Browsing Platform you can get away with quite a lot) and pass that string in with the psuedo protocol html://. The built html can reference images and external css files but all such references must be absolute since there is no base url for the document (unless you include a definition within the html string).
For example, in VB (error checking etc omitted for brevity):
' generate some html and print it
' The html must be complete and valid - any references to images etc by
' url must be absolute references (e.g. you can reference external style sheets)
sHtml = "<html><head><title>ScriptX Sample</title></head><body>"
sHtml = sHtml + "<table border=""0"" width=""100%"" height=""100%""><tr><td align=""center"">"
sHtml = sHtml + "<h1>ScriptX Printing of HTML</h1><p>This report is for:</p><h2>"
sHtml = sHtml + txtName.Text
sHtml = sHtml + "</h2><p>and was printed on:</p><h4>" & Now() & "</h4></td></tr></table></body></html>"
On Error GoTo printError
Set sx = CreateObject("ScriptX.Factory")
Set p = sx.printing
' Some headers and footers.
p.header = "ScriptX - Dynamic PrintHTML"
p.footer = "&d - page: &p of &P"
' The print will actually occur in a separate process.
' tell it it is a string to print by using the html:// psuedo protocol
'
p.printHtml ("html://" + sHtml)
Web service/document
Calling a RESTfull webservice, or requesting any document for printing is trivial - just give PrintHtml the url and it will download and print it with the full glories of the capabilies of the Windows Web Browsing Platform; get as rich with the output as you like. For example, in VB:
Set sx = CreateObject("ScriptX.Factory")
Set p = sx.printing
' Some headers and footers.
p.header = "ScriptX - PrintHTML document"
p.footer = "&d - page: &p of &P"
' The print will actually occur in a separate process.
'
sUrl = sHostUrl + "?name=" & txtName.Text
sUrl = Replace(sUrl, " ", "%20") ' trivial url encoding
p.printHtml (sUrl)
The full (VB) sample is available here.
NOTE: The sample requires ScriptX 6.2 - please contact MeadCo to join the test program for this release (or it may be released by the time you are reading this!).