Simple wrappers on the MeadCo ScriptX objects 'factory', 'factory.printing' and 'secmgr' with additional helper functions.
The implementation is for use in a browser only, not general runtime javascript environments and the code is necessarily 'old-fashioned' as it may find itself running in old versions of IE.
Introduction
The library provides two objects within the MeadCo 'namespace':
Object | Purpose |
---|---|
MeadCo.ScriptX | wraps the classic 'factory' (MeadCo.ScriptX.Utils) and factory.printing (MeadCo.ScriptX.Printing) objects and provides useful helper functions for common processes. |
MeadCo.Licensing | wraps the classic 'secmgr' object. |
MeadCo.ScriptX
The <object /> tag for ScriptX factory is assumed to have an id of 'factory', call MeadCo.ScriptX.Init() (or MeadCo.ScriptX.InitAsync()) to connect the wrappers to underlying implementations - returns true on success.
2 objects will then be available:22
Object | |
---|---|
MeadCo.ScriptX.Utils | the 'factory' object with all the properties and methods as documented |
MeadCo.ScriptX.Printing | the 'factory.printing' object with all the properties and methods as documented, e.g. MeadCo.ScriptX.Printing.header = "My Report header". |
MeadCo.Licensing
The <object /> tag for MeadCo Security Manager is assumed to have an id of 'secmgr', call MeadCo.Licensing.IsLicensed() to test if the licensed is valid for the document and has been installed/accepted.
Use with ScriptX.Services
MeadCo.ScriptXJS supports working with ScriptX.Services or ScriptX.Add-on and so this librray provides an abstraction and helper functions for working seamlessly with either ScriptX.Addon or ScriptX.Services. This works by utilising the MeadCo ScriptX.Services Client Library emulation of 'factory' and 'secmgr'. When both libraries are present, on IE 11 with ScriptX.Addon available it will take priority. On any other browser ScriptX.Services will be used.
Async scenarios with ScriptX.Print Services are supported by providing async wrappers on ScriptX.Addon functions with promises. A promise polyfill is required if promise is not implemented in the browser we recommend (and test with) https://github.com/taylorhakes/promise-polyfill.
Examples
$(window).on('load', function () {
if ( MeadCo.ScriptX.Init() (
{
$("#info").text("ScriptX version: " + MeadCo.ScriptX.GetComponentVersion("scriptx.factory"));
MeadCo.ScriptX.Printing.header =
"MeadCo's ScriptX&b:&p of &P:&bBasic Printing Sample";
MeadCo.ScriptX.Printing.footer =
"The de facto standard for advanced web-based printing";
MeadCo.ScriptX.Printing.orientation = "landscape";
$("#btnprint").click(function() {
MeadCo.ScriptX.PrintPage(false);
}
});
if ( MeadCo.Licensing.IsLicensed() ) {
...
}
else {
MeadCo.Licensing.ReportError();
}
Members
Methods
# static BackgroundPrintHTML(sHtml, fnCallbackopt, dataopt) → {boolean}
Background print the html document contained in the string.
Background print the html document contained in the string. This is a wrapper on the PrintHtmlEX() API using html:// protocol.
Note that processing after call is asynchronous. There is no Promise returning version as the function always returns true (there is no prompting). See MeadCo.ScriptX.WaitForSpoolingComplete() for how to implement synchronous coding.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sHtml |
string | The html to print. The document must be complete and well formed.All resource references in the HTML must be fully qualified unless a base element is included. |
||
fnCallback |
callback |
<optional> |
log to console | Callback function called on progress events fnCallback(nStatus, strStatusData, callbackData) |
data |
object |
<optional> |
"Job" + incrementing index | Data to pass to the event callback function |
always returns true
# static BackgroundPrintURL(sUrl, bPromptopt, fnCallbackopt, dataopt) → {boolean}
Download and print an HTML document in the background.
Download and print an HTML document in the background. This is a wrapper on the PrintHtmlEX() API.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sUrl |
string | The url of the (html) document to download and print |
||
bPrompt |
boolean |
<optional> |
true | bPrompt True if a dialog is to prompt the user to confirm the print |
fnCallback |
callback |
<optional> |
log to console | Callback function called on progress events fnCallback(nStatus, strStatusData, callbackData) |
data |
object |
<optional> |
"Job" + incrementing index | Data to pass to the event callback function |
- Deprecated:
- from 1.4 as the return value will be wrong for service when using prompted printing since dialogs are async. Use BackgroundPrintURL2 if the return value matters
- See:
for prompted printing returns true if the user started the print and it was queued, otherwise false. Always returns true for promptless printing
# static BackgroundPrintURL2(sUrl, bPromptopt, fnCallbackopt, dataopt) → {Promise}
Download and print an HTML document in the background.
Download and print an HTML document in the background. This is a wrapper on the PrintHtmlEX() API.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sUrl |
string | The url of the (html) document to download and print |
||
bPrompt |
boolean |
<optional> |
true | bPrompt True if a dialog is to prompt the user to confirm the print |
fnCallback |
callback |
<optional> |
log to console | Callback function called on progress events fnCallback(nStatus, strStatusData, callbackData) |
data |
object |
<optional> |
"Job" + incrementing index | Data to pass to the event callback function |
Promise object represents boolean with value true for prompted printing and the user started the print and it was queued. For promptless printing always represents true.
# static CloseWindow(oWindow)
Ensures orderly closing of a window in ScriptX.Services by waiting for jobs to complete before the window closes.
Ensures orderly closing of a window in ScriptX.Services by waiting for jobs to complete before the window closes. This is done automatically by ScriptX.Addon
Parameters:
Name | Type | Description |
---|---|---|
oWindow |
object | The window to close |
# static DirectPrintDocument(sPrinterName, sUrl)
Download content from a url and send its contents (e.g.
Download content from a url and send its contents (e.g. ZPL) directly to the printer as a byte stream. This is a wrapper on the printDocument() API
Parameters:
Name | Type | Description |
---|---|---|
sPrinterName |
string | The name of the printer to print to. |
sUrl |
string | url of the file whose contents are to be sent to the printer. The url must be a fully qualified url. |
# static DirectPrintString(sPrinterName, sData)
Directly print a stream of characters to a printer without formatting, pagination or any other processing.
Directly print a stream of characters to a printer without formatting, pagination or any other processing. This is a wrapper on the printString() API
Parameters:
Name | Type | Description |
---|---|---|
sPrinterName |
string | The name of the printer to print to. |
sData |
string | The string (e.g. ZPL) to send directly to the printer as a byte stream |
# static GetAvailablePrinters() → {Array.<string>}
Determnines the names of the printers available pon the device.
Determnines the names of the printers available pon the device. This function wraps the EnumPrinters API in a more convenient form.
array of the names of the available printers available.
# static GetComponentVersion(sComponent) → {string}
Returns the version of an installed component as a dotted version string.
Returns the version of an installed component as a dotted version string. This wraps the deprecated API GetComponentVersion which is available with all versions of ScriptX. Use the recommended alternatives.
Parameters:
Name | Type | Description |
---|---|---|
sComponent |
string | The component name, e.g. "ScriptX.Factory" |
- Deprecated:
- since v7 of ScriptX.Addon. Use ScriptX.Utils.ComponentVersionString or ScriptX.Utils.ScriptXVersion or ScriptX.Utils.SecurityManagerVersion
- See:
Installed version of the component or "Not installed"
# static HasOrientation() → {boolean}
true if the 'orientation' property is available, otherwise the 'portrait' property must be used.
# static Init() → {boolean}
Performs synchronous initialisation by discovering and connecting to either ScriptX.Addon or the MeadCo ScriptX.Services Client Library emulation of the 'factory' object.
Performs synchronous initialisation by discovering and connecting to either ScriptX.Addon or the MeadCo ScriptX.Services Client Library emulation of the 'factory' object.
With ScriptX.Print Services this will use a synchronous (blocking, deprecated) call to the server.
From v1.9.0 this function also initialises licensing when ScriptX.Services is being used by the browser to reduce required coding updates where MeadCo.ScriptX.Init() has been used.
true if initialisation succeeded and implementations of the MeadCo ScriptX factory and printing objects are available, false if failed
# static InitAsync() → {Promise}
Performs asynchronous initialisation by discovering and connecting to either ScriptX.Addon or ScriptX.Services.
Performs asynchronous initialisation by discovering and connecting to either ScriptX.Addon or ScriptX.Services.
From v1.9.0 this function also initialises licensing when ScriptX.Services is being used by the browser to reduce required coding updates where MeadCo.ScriptX.Init() has been used. To obtain the license read the property MeadCo.Licensing.LicMgr.License
Promise object represents enum Connection with value of the connection found (NONE, ADDON or SERVICES)
# static InitWithVersion(strVersion) → {boolean}
Initialises the library and ensures that the installed version is at least some version.
Initialises the library and ensures that the installed version is at least some version. If ScriptX is available but not the required version an alert dialog is displayed.
Parameters:
Name | Type | Description |
---|---|---|
strVersion |
string | minimum required version number (e.g. "7.1.2.65") |
- Deprecated:
- from version 1.8.0
true if initialisation succeeded and implementations of the MeadCo ScriptX factory and printing objects are available at the required version of higher, false if failed
# static IsComponentVersion(strComponentName, strVersionRequired) → {boolean}
Determine if the installed version of a COM component is at least the given version
.Determine if the installed version of a COM component is at least the given version
Parameters:
Name | Type | Description |
---|---|---|
strComponentName |
string | The name of the COM Component |
strVersionRequired |
string | minimum version in dotted form |
true is the component is installed and at least the version required.
# static IsServices(strVersion) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
strVersion |
string |
true if ScriptX.Services is/will be used
# static IsServicesVersion(strVersion) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
strVersion |
string |
true if the services server in use is at least strVersion where strVersion is a dotted version number (e.g. "7.1.2.65")
# static IsVersion(strVersion) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
strVersion |
string |
true if the installed version is at least strVersion where strVersion is a dotted version number (e.g. "7.1.2.65")
# static PageSetup() → {boolean}
Invokes a Page Setup Dialog.
Invokes a Page Setup Dialog. This is a wrapper on the PageSetup API
- Deprecated:
- from 1.4 as the return value will be wrong for service since dialogs are async. Use PageSetup2 if the return value matters
- See:
-
- PageSetup API
- PageSetup2
true if the user closed the dialog with the OK button, otherwise false.
# static PageSetup2() → {Promise}
Invokes a Page Setup Dialog.
Invokes a Page Setup Dialog. This is a wrapper on the PageSetup API
Promise object represents boolean with value true if the user closed the dialog with the OK button, otherwise false.
# static PreviewPage()
Opens a preview of the printed current document (page).
Opens a preview of the printed current document (page). This is a wrapper on the Preview() API.
# static PreviewPage(frame)
Opens a preview of the printed frame.
Opens a preview of the printed frame. This is a wrapper on the Preview() API.
Parameters:
Name | Type | Description |
---|---|---|
frame |
string | object | The frame object or the name of the frame to be printed. |
# static PrintFrame(frame, bPromptopt) → {boolean}
Print the content of the frame, with optional prompting (no prompt in the internetzone requires a license).
Print the content of the frame, with optional prompting (no prompt in the internetzone requires a license). This is a wrapper on the Print API.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
frame |
string | object | The frame object or the name of the frame to be printed. |
||
bPrompt |
boolean |
<optional> |
true | bPrompt True if a dialog is to prompt the user to confirm the print |
- Deprecated:
- from 1.4 as the return value will be wrong for service when using prompted printing since dialogs are async. Use PrintFrame2 if the return value matters
- See:
true if print was started, otherwise false
# static PrintFrame2(frame, bPromptopt) → {Promise}
Print the content of the frame, with optional prompting (no prompt in the internetzone requires a license).
Print the content of the frame, with optional prompting (no prompt in the internetzone requires a license). This is a wrapper on the Print API.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
frame |
string | object | The frame object or the name of the frame to be printed. |
||
bPrompt |
boolean |
<optional> |
true | bPrompt True if a dialog is to prompt the user to confirm the print |
Promise object represents boolean with value true if the print was started
# static PrintPage(bPromptopt) → {boolean}
Print the current document, with optional prompting (no prompt in the internetzone requires a license).
Print the current document, with optional prompting (no prompt in the internetzone requires a license). This is a wrapper on the Print API.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
bPrompt |
boolean |
<optional> |
true | bPrompt True if a dialog is to prompt the user to confirm the print |
- Deprecated:
- from 1.4 as the return value will be wrong for service since dialogs are async. Use PrintPage2 if the return value matters
- See:
true if print was started, otherwise false
# static PrintPage2(bPromptopt) → {Promise}
Print the current document, with optional prompting (no prompt in the internetzone requires a license).
Print the current document, with optional prompting (no prompt in the internetzone requires a license). This is a wrapper on the Print API.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
bPrompt |
boolean |
<optional> |
true | bPrompt |
Promise object represents boolean with value true if the print was started
# static PrintSetup() → {boolean}
Invokes a Print Setup Dialog.
Invokes a Print Setup Dialog. This is a wrapper on the PrintSetup API
- Deprecated:
- from 1.4 as the return value will be wrong for service since dialogs are async. Use PrintSetup2 if the return value matters
- See:
-
- PrintSetup API
- PrintSetup2
true if the user closed the dialog with the OK button, otherwise false.
# static PrintSetup2() → {Promise}
Invokes a Print Setup Dialog.
Invokes a Print Setup Dialog. This is a wrapper on the PrintSetup API
Promise object represents boolean with value true if the user closed the dialog with the OK button, otherwise false.
# static ScriptXVersion() → {string}
Get the installed version of ScriptX
.Get the installed version of ScriptX
Installed version or "Not installed"
# static SecurityManagerVersion() → {string}
Get the installed version of MeadCo Security Manager
.Get the installed version of MeadCo Security Manager
Installed version or "Not installed"
# static ServicesVersion() → {string}
If services is in use, returns the version of the services server.
If services is in use, returns the version of the services server. If addon is in use returns ""
Requires services 2.9 or later, earlier versions will return the client library version (1.x)
# static SetContentAuthorisationCookie(strCookie)
With ScriptX.Addon, printHtml(Ex) and printPdf(Ex) inherit authorisation cookies from the hosting browser.
With ScriptX.Addon, printHtml(Ex) and printPdf(Ex) inherit authorisation cookies from the hosting browser. This does not happen with ScriptX.Services and in modern uses the authorisation cookie is hidden from javascript so cannot be automated. The cookie must be exposed in the HTML and passed in with a call to this function.
Parameters:
Name | Type | Description |
---|---|---|
strCookie |
string | The cookie in form name=value. use "" to remove use of cookie authorisation |
# static StartAsync(settings) → {Promise}
Perform full asynchronous initialisation - for services, connecting to a server, then for addon and services connecting to a secmgr implementation, checking for a license and connecting to factory and printing implementations.
Perform full asynchronous initialisation - for services, connecting to a server, then for addon and services connecting to a secmgr implementation, checking for a license and connecting to factory and printing implementations.
Lastly apply print settings as defined.
This is the preferred library initialisation call especially when wishing to support working with ScriptX.Services as it a) ensures a license is available before attempting services calls and b) is asynchronous and c) hides a lot of code in a simple call.
Parameters:
Name | Type | Description |
---|---|---|
settings |
StartupSettings |
Promise object presents .connection (implementation type) and .license (detail) to resolve and error message to reject
Example
$(window).on('load', function () {
MeadCo.ScriptX.StartAsync({
serviceConnection: {
serverUrl: "http://127.0.0.1:41191",
licenseGuid: "{370000ED-D40C-43D4-B3D3-F2E7D2EFF47D}", // invalid example, use same as for addon
licenseRevision: 0,
licensePath: "warehouse"
},
printSettings: {
header: "Page &p of &P",
footer: "&D",
pageSetup: {
orientation: "landscape"
}
}
})
.then(function() {
$("#btn-print").click(function() {
MeadCo.ScriptX.PrintPage(false);
});
})
.catch(function(e) {
alert("An error occurred, printing will not be available.\n\n"+e);
});
# static Version() → {string}
the installed version number of ScriptX (if services is in use then returns the version of ScriptX.Addon being emulated).
# static WaitForSpoolingComplete() → {Promise}
Waits for all pending spooling and download operations originated with Print, PrintHTML and BatchPrintPDF to complete.
Waits for all pending spooling and download operations originated with Print, PrintHTML and BatchPrintPDF to complete. This is useful for providing 'busy' UI or waiting for all jobs to complete before closing a window.
This is a wrapper on the common use (no arguments) of the WaitForSpoolingComplete API and returns a Promise so that it can work with both ScriptX.Addon and ScriptX.Services
- See:
Promise object represents boolean with value true if all jobs have been completed (will always be true).
Example
MeadCo.ScriptX.PrintPage(false);
MeadCo.ScriptX.WaitForSpoolingComplete().finally(function(bAllJobsComplete) {
self.close();
})
Type Definitions
# Connection
Enum to describe the implementation being wrapped : .Addon or .Services
.Enum to describe the implementation being wrapped : .Addon or .Services
Properties:
Name | Type | Description |
---|---|---|
NONE |
number | 0 no connection wrapped (initialise not called or failed) |
ADDON |
number | 1 ScriptX.Addon is being wrapped |
SERVICE |
number | 2 ScriptX.Services is being wrapped |
# MeasurementUnits
Enum to describe the units used on measurements.
Enum to describe the units used on measurements. These values do match the values used by the MeadCo ScriptX COM Servers.
Properties:
Name | Type | Description |
---|---|---|
DEFAULT |
number | 0 use the default at the print server |
MM |
number | 1 millimeters |
INCHES |
number | 2 inches |
# PageSetup
Describe pagesetup - orientation and the margins to use
.Describe pagesetup - orientation and the margins to use
Properties:
Name | Type | Description |
---|---|---|
units |
MeasurementUnits | The units used for margins |
orientation |
string | valid values are 'landscape' and 'portrait' |
margins |
Margins | the margins to use |
# PrintSettings
Properties:
Name | Type | Description |
---|---|---|
header |
string | |
footer |
string | |
pageSetup |
PageSetup |
# ServiceConnection
Properties:
Name | Type | Description |
---|---|---|
serverUrl |
string | |
licenseGuid |
string | |
licenseRevision |
number | |
licensePath |
string |
# StartupSettings
Properties:
Name | Type | Description |
---|---|---|
serviceConnection; |
ServiceConnection | |
printSettings |
PrintSettings |