Namespace

MeadCo.ScriptX

MeadCo.ScriptX

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.

View Source meadco-scriptx.js, line 1

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

.

The discovered connection - NONE, ADDON or SERVICE

View Source meadco-scriptx.js, line 186

# static constant LibVersion

The semver version of this library

.

The semver version of this library

View Source meadco-scriptx.js, line 193

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

See:

View Source meadco-scriptx.js, line 691

always returns true

boolean

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

View Source meadco-scriptx.js, line 628

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

boolean

# 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

See:

View Source meadco-scriptx.js, line 653

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.

Promise

# 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

View Source meadco-scriptx.js, line 898

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

See:

View Source meadco-scriptx.js, line 728

# 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

See:

View Source meadco-scriptx.js, line 710

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

See:

View Source meadco-scriptx.js, line 929

array of the names of the available printers available.

Array.<string>

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

View Source meadco-scriptx.js, line 955

Installed version of the component or "Not installed"

string

# static HasOrientation() → {boolean}

View Source meadco-scriptx.js, line 916

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

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.

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.

See:

View Source meadco-scriptx.js, line 283

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

boolean

# 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

View Source meadco-scriptx.js, line 332

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

Promise

# 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

View Source meadco-scriptx.js, line 395

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

boolean

# 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

View Source meadco-scriptx.js, line 1006

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

boolean

# static IsServices(strVersion) → {boolean}

Parameters:
Name Type Description
strVersion string

View Source meadco-scriptx.js, line 435

true if ScriptX.Services is/will be used

boolean

# static IsServicesVersion(strVersion) → {boolean}

Parameters:
Name Type Description
strVersion string

View Source meadco-scriptx.js, line 480

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

boolean

# static IsVersion(strVersion) → {boolean}

Parameters:
Name Type Description
strVersion string

View Source meadco-scriptx.js, line 425

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

boolean

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

View Source meadco-scriptx.js, line 750

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

boolean

# static PageSetup2() → {Promise}

Invokes a Page Setup Dialog.

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

See:

View Source meadco-scriptx.js, line 784

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

Promise

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

See:

View Source meadco-scriptx.js, line 549

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

See:

View Source meadco-scriptx.js, line 606

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

View Source meadco-scriptx.js, line 564

true if print was started, otherwise false

boolean

# 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

See:

View Source meadco-scriptx.js, line 580

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

Promise

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

View Source meadco-scriptx.js, line 509

true if print was started, otherwise false

boolean

# 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

See:

View Source meadco-scriptx.js, line 524

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

Promise

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

View Source meadco-scriptx.js, line 765

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

boolean

# static PrintSetup2() → {Promise}

Invokes a Print Setup Dialog.

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

See:

View Source meadco-scriptx.js, line 820

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

Promise

# static ScriptXVersion() → {string}

Get the installed version of ScriptX

.

Get the installed version of ScriptX

View Source meadco-scriptx.js, line 986

Installed version or "Not installed"

string

# static SecurityManagerVersion() → {string}

Get the installed version of MeadCo Security Manager

.

Get the installed version of MeadCo Security Manager

View Source meadco-scriptx.js, line 996

Installed version or "Not installed"

string

# 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)

View Source meadco-scriptx.js, line 463

string

# 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

View Source meadco-scriptx.js, line 494

# 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

View Source meadco-scriptx.js, line 199

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

Promise
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}

View Source meadco-scriptx.js, line 414

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

string

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

View Source meadco-scriptx.js, line 864

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

Promise
Example
MeadCo.ScriptX.PrintPage(false);
MeadCo.ScriptX.WaitForSpoolingComplete().finally(function(bAllJobsComplete) {
 self.close();
})

Type Definitions

number

# 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

View Source meadco-scriptx.js, line 90

# Margins

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

View Source meadco-scriptx.js, line 124

number

# 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

View Source meadco-scriptx.js, line 107

Object

# 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

View Source meadco-scriptx.js, line 134

Object

# PrintSettings

Properties:
Name Type Description
header string
footer string
pageSetup PageSetup

View Source meadco-scriptx.js, line 145

Object

# ServiceConnection

Properties:
Name Type Description
serverUrl string
licenseGuid string
licenseRevision number
licensePath string

View Source meadco-scriptx.js, line 153

Object

# StartupSettings

Properties:
Name Type Description
serviceConnection; ServiceConnection
printSettings PrintSettings

View Source meadco-scriptx.js, line 163