Applying the license
To apply a license to an application, the MeadCo Security Manager object is created and the Apply method called.
Apply
Description
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.
Syntax
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. |
Sample
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.
Printing content in a web browser control
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 printHtml method
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.
On the fly
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>"
sHtml = sHtml + "<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, or as (Visual Basic.NET) here.
c# samples
A small set of c# samples is available here, these illustrate using ScriptX in an embedded web browser control and using printHtml().