April 2005 (Version 6.2 and later)
This document applies to ScriptX Printing v6.2.433.9 or later. If you are using an earlier version, please contact MeadCo for an upgrade.
There are two scenarios in which ScriptX can be used with a desktop (client) application; unlicensed (free) and licensed.
In unlicensed (free) usage, ScriptX can be used with a web browser control displayed within the application.
The ScriptX object may be placed on the HTML document displayed in the control and utilised by script on the document, or code from the host application, or the ScriptX object can be injected into a loaded HTML document and then its properties and methods called from the host application.
In both these cases, it is the HTML document displayed in the web browser control that is printed.
The following VB code shows the principle; assume that the following routine is called when a 'Print' button is clicked and that a Web Browser control with identifier 'WebBrowser1' is present on the Form and has a document completely loaded:
Private Sub commandPrint_Click() Dim factory As Object Dim b ' Attempt to find a ScriptX factory object on the page. ' factory is the standard id used so this will probably find any already ' existing object on the page - or the one we previously created ' if print is hit twice. Set factory = WebBrowser1.Document.getElementById("factory") If factory Is Nothing Then ' There isn't one, so create one. WebBrowser1.Document.body.insertAdjacentHTML "beforeEnd", "<object id=""factory"" style=""display:none"" classid=""clsid:1663ed61-23eb-11d2-b92f-008048fdd814""></object>" Set factory = WebBrowser1.Document.getElementById("factory") End If ' use some of the free features, like headers and footers factory.printing.header = "This is my header" factory.printing.footer = "Page Footer: &D - &P" ' We'll ask for no prompt, but, unlicensed, anything from the Internet Zone ' will get a prompt. Intranet/trusted/my computer content *will not* b = factory.printing.Print(False) End Sub
A complete sample is available here.
Licensed use allows you to use all the features of ScriptX is any way you choose. There are two basic scenarios:
For either of these scenarios, a license is required. Two types of license are available:
For development purposes it is suggested that a machine license is obtained for the machines on which development takes place.
To apply a license to an application, the MeadCo Security Manager object is created and the Apply method called.
Applies a license for use in a running process. This method cannot be called from a web page.
Due to the asynchronous behaviour of some ScriptX methods it is not recommended that the license is applied within a sub-routine that is making ScriptX calls; the license may be required after the sub-routine exits. The license should be available for the lifetime of the process - a global variable for the MeadCo Security Manager object is recommended.
secMgr.Apply(sLicUrl,sGUID,nRevision)
Parameter Description sLicUrl String. Optional. The url at which the license file may be found. This must be an absolute location and may include, for example, the res: protocol to include a license within the application's resources.
This value is only required for application licenses. A machine license should be pre-installed and this value given as ""
sGuid String. Required. The GUID of the license - this will be supplied with the license file. nRevision Number. Required. The revision number of the license - this will be supplied with the license.
Taking Visual Basic as an example, a suitable point for applying the license is during the form load event:
Option Explicit ' we will late bind to MeadCo SecMgr ' What is important is that the object is global ' so that it is available to license all calls within the process. ' Dim secMgr As Object Private Sub Form_Load() ' License this process On Error GoTo noLicense Set secMgr = CreateObject("MeadCo.SecMgr") ' For evaluation, ask MeadCo for a machine license, install it and reference it like this... ' Call secMgr.Apply("", "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}", 17) ' For real (compiled exe) use, buy an application license. By applying the license, ' this application process will then become licensed. ' ' A url to the license file must be passed in. For simplicity we assume that the license file ' resides in the same directory as this application but it could be put in the exe as ' a resource and the res: protocol used. Call secMgr.Apply(CurDir() & "\lic.mlf", "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}", 2) Exit Sub noLicense: MsgBox "Unable to apply the ScriptX License (" & (CurDir() & "\lic.mlf") & ") because [" & Err.Description & "]" End Sub
Once the license is succesfully applied, then the features enabled by the license may be used within the application.
For controlled printing of content displayed within the web browser control, the techniques discussed under unlicensed use may be used; using the ScriptX object declared within the HTML page or a ScriptX object injected into a page; the license allows additional methods and properties (and in addition, MaxiPT templates).
Two complete (Visual basic) samples that illustrate licensed usage are available here and here.
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:
To create html on the fly, simply build the complete html as a string (it should be well formed, 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 that 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 (Visual Basic) sample is available
here.