MeadCo.ScriptX

Namespace

MeadCo.ScriptX

Simple wrappers on the MeadCo ScriptX objects 'factory', 'factory.printing' and 'secmgr' with additional helper functions.

Description:
  • 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.

Source:
Examples

Example of initialisation and use of wrappers

 $(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);
  }
});

Example of MeadCo.Licensing.IsLicensed()

if ( MeadCo.Licensing.IsLicensed() ) {
 	...
}
else {
   MeadCo.Licensing.ReportError();
}

Members

(static, readonly) Connector

The discovered connection - NONE, ADDON or SERVICE

.

Description:
  • The discovered connection - NONE, ADDON or SERVICE

Source:

The discovered connection - NONE, ADDON or SERVICE

(static, constant) LibVersion

The semver version of this library

.

Description:
  • The semver version of this library

Source:

The semver version of this library

Methods

(static) BackgroundPrintHTML(sHtml, fnCallbackopt, dataopt) → {boolean}

Background print the html document contained in the string.

Description:
  • 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.

Source:
See:
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

Returns:

always returns true

Type
boolean

(static) BackgroundPrintURL(sUrl, bPromptopt, fnCallbackopt, dataopt) → {boolean}

Download and print an HTML document in the background.

Description:
  • Download and print an HTML document in the background. This is a wrapper on the PrintHtmlEX() API.

Source:
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:
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

Returns:

for prompted printing returns true if the user started the print and it was queued, otherwise false. Always returns true for promptless printing

Type
boolean

(static) BackgroundPrintURL2(sUrl, bPromptopt, fnCallbackopt, dataopt) → {Promise}

Download and print an HTML document in the background.

Description:
  • Download and print an HTML document in the background. This is a wrapper on the PrintHtmlEX() API.

Source:
See:
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

Returns:

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.

Type
Promise

(static) CloseWindow(oWindow)

Ensures orderly closing of a window in ScriptX.Services by waiting for jobs to complete before the window closes.

Description:
  • 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

Source:
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.

Description:
  • 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

Source:
See:
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.

Description:
  • Directly print a stream of characters to a printer without formatting, pagination or any other processing. This is a wrapper on the printString() API

Source:
See:
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.

Description:
  • Determnines the names of the printers available pon the device. This function wraps the EnumPrinters API in a more convenient form.

Source:
See:
Returns:

array of the names of the available printers available.

Type
Array.<string>

(static) GetComponentVersion(sComponent) → {string}

Returns the version of an installed component as a dotted version string.

Description:
  • 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.

Source:
Deprecated:
  • since v7 of ScriptX.Addon. Use ScriptX.Utils.ComponentVersionString or ScriptX.Utils.ScriptXVersion or ScriptX.Utils.SecurityManagerVersion
See:
Parameters:
Name Type Description
sComponent string

The component name, e.g. "ScriptX.Factory"

Returns:

Installed version of the component or "Not installed"

Type
string

(static) HasOrientation() → {boolean}

Source:
Returns:

true if the 'orientation' property is available, otherwise the 'portrait' property must be used.

Type
boolean

(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.

Description:
  • 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.

Source:
See:
Returns:

true if initialisation succeeded and implementations of the MeadCo ScriptX factory and printing objects are available, false if failed

Type
boolean

(static) InitAsync() → {Promise}

Performs asynchronous initialisation by discovering and connecting to either ScriptX.Addon or ScriptX.Services.

Description:
  • 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

Source:
Returns:

Promise object represents enum Connection with value of the connection found (NONE, ADDON or SERVICES)

Type
Promise

(static) InitWithVersion(strVersion) → {boolean}

Initialises the library and ensures that the installed version is at least some version.

Description:
  • 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.

Source:
Deprecated:
  • from version 1.8.0
Parameters:
Name Type Description
strVersion string

minimum required version number (e.g. "7.1.2.65")

Returns:

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

Type
boolean

(static) IsComponentVersion(strComponentName, strVersionRequired) → {boolean}

Determine if the installed version of a COM component is at least the given version

.

Description:
  • Determine if the installed version of a COM component is at least the given version

Source:
Parameters:
Name Type Description
strComponentName string

The name of the COM Component

strVersionRequired string

minimum version in dotted form

Returns:

true is the component is installed and at least the version required.

Type
boolean

(static) IsServices(strVersion) → {boolean}

Source:
Parameters:
Name Type Description
strVersion string
Returns:

true if ScriptX.Services is/will be used

Type
boolean

(static) IsServicesVersion(strVersion) → {boolean}

Source:
Parameters:
Name Type Description
strVersion string
Returns:

true if the services server in use is at least strVersion where strVersion is a dotted version number (e.g. "7.1.2.65")

Type
boolean

(static) IsVersion(strVersion) → {boolean}

Source:
Parameters:
Name Type Description
strVersion string
Returns:

true if the installed version is at least strVersion where strVersion is a dotted version number (e.g. "7.1.2.65")

Type
boolean

(static) PageSetup() → {boolean}

Invokes a Page Setup Dialog.

Description:
  • Invokes a Page Setup Dialog. This is a wrapper on the PageSetup API

Source:
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:
Returns:

true if the user closed the dialog with the OK button, otherwise false.

Type
boolean

(static) PageSetup2() → {Promise}

Invokes a Page Setup Dialog.

Description:
  • Invokes a Page Setup Dialog. This is a wrapper on the PageSetup API

Source:
See:
Returns:

Promise object represents boolean with value true if the user closed the dialog with the OK button, otherwise false.

Type
Promise

(static) PreviewPage()

Opens a preview of the printed current document (page).

Description:
  • Opens a preview of the printed current document (page). This is a wrapper on the Preview() API.

Source:
See:

(static) PreviewPage(frame)

Opens a preview of the printed frame.

Description:
  • Opens a preview of the printed frame. This is a wrapper on the Preview() API.

Source:
See:
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).

Description:
  • 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.

Source:
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:
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

Returns:

true if print was started, otherwise false

Type
boolean

(static) PrintFrame2(frame, bPromptopt) → {Promise}

Print the content of the frame, with optional prompting (no prompt in the internetzone requires a license).

Description:
  • 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.

Source:
See:
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

Returns:

Promise object represents boolean with value true if the print was started

Type
Promise

(static) PrintPage(bPromptopt) → {boolean}

Print the current document, with optional prompting (no prompt in the internetzone requires a license).

Description:
  • Print the current document, with optional prompting (no prompt in the internetzone requires a license). This is a wrapper on the Print API.

Source:
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:
Parameters:
Name Type Attributes Default Description
bPrompt boolean <optional>
true

bPrompt True if a dialog is to prompt the user to confirm the print

Returns:

true if print was started, otherwise false

Type
boolean

(static) PrintPage2(bPromptopt) → {Promise}

Print the current document, with optional prompting (no prompt in the internetzone requires a license).

Description:
  • Print the current document, with optional prompting (no prompt in the internetzone requires a license). This is a wrapper on the Print API.

Source:
See:
Parameters:
Name Type Attributes Default Description
bPrompt boolean <optional>
true

bPrompt

Returns:

Promise object represents boolean with value true if the print was started

Type
Promise

(static) PrintSetup() → {boolean}

Invokes a Print Setup Dialog.

Description:
  • Invokes a Print Setup Dialog. This is a wrapper on the PrintSetup API

Source:
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:
Returns:

true if the user closed the dialog with the OK button, otherwise false.

Type
boolean

(static) PrintSetup2() → {Promise}

Invokes a Print Setup Dialog.

Description:
  • Invokes a Print Setup Dialog. This is a wrapper on the PrintSetup API

Source:
See:
Returns:

Promise object represents boolean with value true if the user closed the dialog with the OK button, otherwise false.

Type
Promise

(static) ScriptXVersion() → {string}

Get the installed version of ScriptX

.

Description:
  • Get the installed version of ScriptX

Source:
Returns:

Installed version or "Not installed"

Type
string

(static) SecurityManagerVersion() → {string}

Get the installed version of MeadCo Security Manager

.

Description:
  • Get the installed version of MeadCo Security Manager

Source:
Returns:

Installed version or "Not installed"

Type
string

(static) ServicesVersion() → {string}

If services is in use, returns the version of the services server.

Description:
  • 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)

Source:
Returns:
Type
string

(static) SetContentAuthorisationCookie(strCookie)

With ScriptX.Addon, printHtml(Ex) and printPdf(Ex) inherit authorisation cookies from the hosting browser.

Description:
  • 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.

Source:
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.

Description:
  • 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.

Source:
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);
     });
Parameters:
Name Type Description
settings StartupSettings
Returns:

Promise object presents .connection (implementation type) and .license (detail) to resolve and error message to reject

Type
Promise

(static) Version() → {string}

Source:
Returns:

the installed version number of ScriptX (if services is in use then returns the version of ScriptX.Addon being emulated).

Type
string

(static) WaitForSpoolingComplete() → {Promise}

Waits for all pending spooling and download operations originated with Print, PrintHTML and BatchPrintPDF to complete.

Description:
  • 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

Source:
See:
Example
MeadCo.ScriptX.PrintPage(false);
MeadCo.ScriptX.WaitForSpoolingComplete().finally(function(bAllJobsComplete) {
 self.close();
})
Returns:

Promise object represents boolean with value true if all jobs have been completed (will always be true).

Type
Promise

Type Definitions

Connection

Enum to describe the implementation being wrapped : .Addon or .Services

.

Description:
  • Enum to describe the implementation being wrapped : .Addon or .Services

Source:
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

Enum to describe the implementation being wrapped : .Addon or .Services

Type:
  • number

Margins

Source:
Properties:
Name Type Description
left number
right number
top number
bottom number

MeasurementUnits

Enum to describe the units used on measurements.

Description:
  • Enum to describe the units used on measurements. These values do match the values used by the MeadCo ScriptX COM Servers.

Source:
Properties:
Name Type Description
DEFAULT number

0 use the default at the print server

MM number

1 millimeters

INCHES number

2 inches

Enum to describe the units used on measurements. These values do match the values used by the MeadCo ScriptX COM Servers.

Type:
  • number

PageSetup

Describe pagesetup - orientation and the margins to use

.

Description:
  • Describe pagesetup - orientation and the margins to use

Source:
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

Describe pagesetup - orientation and the margins to use

Type:
  • Object

PrintSettings

Source:
Properties:
Name Type Description
header string
footer string
pageSetup PageSetup
Type:
  • Object

ServiceConnection

Source:
Properties:
Name Type Description
serverUrl string
licenseGuid string
licenseRevision number
licensePath string
Type:
  • Object

StartupSettings

Source:
Properties:
Name Type Description
serviceConnection; ServiceConnection
printSettings PrintSettings
Type:
  • Object