Namespace

MeadCo.ScriptX.Print

MeadCo.ScriptX.Print

MeadCo.ScriptX.Print

A static class wrapping calls to the server API.

Requires: meadco-core.js

Includes processing of calls to the print api that return "printing to file" including collecting the file output.

Provides attribute based connection to the server.

Synchronous AJAX calls are deprecated in all browsers but may be useful to "quick start" use of older code. It is recommended that code is moved to using asynchronous calls as soon as practical. The MeadCoScriptXJS library can assist with this as it delivers promise rather than callback based code.

View Source meadco-scriptxprint.js, line 1

Members

# static readonly activeJobs

The number of jobs there are actgive at the server for this client (same as MeadCo.ScriptX.Print.queue.length)

Properties:
Name Type Description
activeJobs int

the number of jobs

View Source meadco-scriptxprint.js, line 2186

# static authorisationCookie

Get/set the cookie to be used to authorise access to protected content

Properties:
Name Type Description
authorisationCookie string

the cookie in the form name=value

View Source meadco-scriptxprint.js, line 1655

# static readonly availablePrinterNames

Get the list of printers availablefrom the server.

Properties:
Name Type Description
availablePrinterNames Array.<string>

an array of strings of the names of the available printers

View Source meadco-scriptxprint.js, line 1957

# static deviceSettings

Get/set the cached device settings (papersize etc) for the currently active printer

Properties:
Name Type Description
deviceSettings DeviceSettingsObject

(see API /api/vi/printhtml/deviceInfo/ )

View Source meadco-scriptxprint.js, line 1756

# static readonly isConnected

true if the library has succesfully connected to a server and the default device settings obtained.

Properties:
Name Type Description
isConnected bool

true if the library has succesfully connected to a server.

View Source meadco-scriptxprint.js, line 1946

# static readonly isSpooling

Get if print is still 'spooling'.still queued at the server

Properties:
Name Type Description
isSpooling bool

View Source meadco-scriptxprint.js, line 2228

# static jobFileName

Get/set the name to use on the next job

Properties:
Name Type Description
jobFileName string

View Source meadco-scriptxprint.js, line 2301

# static onErrorAction

Get/set the action to take when an error occurs

Properties:
Name Type Description
onErrorAction ErrorAction

the action

View Source meadco-scriptxprint.js, line 1611

# static printerName

Get/set the currently active printer

Properties:
Name Type Description
printerName string

The name of the current printer in use.

View Source meadco-scriptxprint.js, line 1668

# static readonly queue

The list of jobs currently active at the server for this client

Properties:
Name Type Description
queue Array.<object>

array of jobs

View Source meadco-scriptxprint.js, line 2174

# static queueGapResetTime

Get/set the time since last print call after which the job spacing timeout is reset

Properties:
Name Type Description
queueGapResetTime number

View Source meadco-scriptxprint.js, line 2287

# static queueTimeoutSpacing

Get/set the timeout between jobs when there is a series of print calls and maintaining the output order is required. The default is 750ms. On slow systems/slow connections this may need to be increased.

Properties:
Name Type Description
queueTimeoutSpacing number

View Source meadco-scriptxprint.js, line 2273

# static serviceUrl

Get the full url of the ScriptX.Services server connected to

Properties:
Name Type Description
serviceUrl string

View Source meadco-scriptxprint.js, line 1724

# static version

Get the version of this module as a string major.minor.hotfix.build

Properties:
Name Type Description
version string

View Source meadco-scriptxprint.js, line 1714

Methods

# static addPrinterConnection(sShareName)

Add a printer for the user. The printer driver must already be available.

Parameters:
Name Type Description
sShareName any

View Source meadco-scriptxprint.js, line 1961

# static addPrinterConnectionAsync(sShareName, onSuccess, onFail)

Add a printer for the user. The printer driver must already be available.

Parameters:
Name Type Description
sShareName any
onSuccess any
onFail any

View Source meadco-scriptxprint.js, line 1983

# static connect(serverUrl, licenseGuid)

Specify the server to use and the subscription/license id.

Attempt to connect to the defined ScriptX.Services server and obtain the device settings for the default printer. This call is synchronous and therefore not recommended. Use connectAsync()

Parameters:
Name Type Description
serverUrl string

the 'root' url to the server (the api path will be added by the library)

licenseGuid string

the license/subscription identifier

View Source meadco-scriptxprint.js, line 1820

# static connectAsync(serverUrl, licenseGuid, resolve, reject)

Specify the server to use and the subscription/license id.

Attempt to connect to the defined ScriptX.Services server and obtain the device settings for the default printer.

Parameters:
Name Type Description
serverUrl string

the 'root' url to the server (the api path will be added by the library)

licenseGuid string

the license/subscription identifier

resolve function

function to call on success, dataObject contains the device settings for the default device.

reject function

function to call on failure

View Source meadco-scriptxprint.js, line 1852

# static connectDeviceAndPrinters(deviceInfo, arPrinters)

Cache the given device info and available printers in this static class instance

Used by libraries that call api/v1/printHtml/htmlPrintDefaults

Parameters:
Name Type Description
deviceInfo object

the device name and settings (papersize etc)

arPrinters array

the names of the available printers

View Source meadco-scriptxprint.js, line 1923

# static connectLite(serverUrl, licenseGuid)

Specify the server and the subscription/license id to use on AJAX calls. No call is made in this function

Parameters:
Name Type Description
serverUrl string

the 'root' url to the server (the api path will be added by the library)

licenseGuid string

the license/subscription identifier

View Source meadco-scriptxprint.js, line 1836

# static connectTestAsync(serverUrl, resolve, reject)

Test if there is a MeadCo PrintHtml API server at the url

Parameters:
Name Type Description
serverUrl string

the 'root' url to the server (the api path will be added by the library)

resolve function

function to call on success

reject function

function to call on failure

View Source meadco-scriptxprint.js, line 1869

# static deviceSettingsFor(sPrinterName) → {DeviceSettingsObject}

Get the device settings (papersize etc) for the named printer. This call is synchronous and not recommended.

Parameters:
Name Type Description
sPrinterName string

the name of the printer device to return the settings for

View Source meadco-scriptxprint.js, line 1764

object with properties

DeviceSettingsObject

# static ensureSpoolingStatus() → {object}

Make sure that spooling status is locked active while asynchronous UI that may start printing is displayed by placing a lock on the queue.

View Source meadco-scriptxprint.js, line 2190

a fake job to lock the spooling status on

object
Example
var lock = MeadCo.ScriptX.Print.ensureSpoolingStatus
ShowAsyncUI(function() {
 MeadCo.ScriptX.Print.freeSpoolStatus(lock);
});

# static freeSpoolStatus(lock)

Remove a lock on the queue that was created by a call to ensureSpoolingStatus().

Parameters:
Name Type Description
lock object

the lock object returned by ensureSpoolingStatus()

View Source meadco-scriptxprint.js, line 2210

# static getFromServer(sPrintHtmlApi, async, onSuccess, onFail)

Call a /printHtml API on the server with GET

Parameters:
Name Type Description
sPrintHtmlApi string

the api to call on the connected server

async bool

true for asynchronous call, false for synchronous

onSuccess function

function to call on success

onFail function

function to call on failure

View Source meadco-scriptxprint.js, line 2009

# static parseAjaxError(logText, jqXhr, textStatus, errorThrown) → {string}

Extract the error text from jQuery AJAX response

Parameters:
Name Type Description
logText string

The lead-in text for a console.log entry

jqXhr object

jQuery ajax header

textStatus string

textStatus result determined by jQuery

errorThrown string

The server exception dewtermined by jQuery

View Source meadco-scriptxprint.js, line 2091

The error text to display

string

# static printDirect(contentType, content, fnDone) → {boolean}

Post a request to the server to print a string directly to the current printer. The print is synchronous at the server and is completed (sent to the printer) when the api returns.

Parameters:
Name Type Description
contentType ContentType

enum type of content given (string or url)

content string

the content - a url, or string containing e.g. zpl.

fnDone function

function to call when printing complete, arg is null on no error, else error message

View Source meadco-scriptxprint.js, line 2077

  • true if a print was started (otherwise an error will be thrown) *
boolean

# static printHtml(contentType, content, htmlPrintSettings, fnDone, fnProgress, data) → {boolean}

Post a request to the server to print some html and monitor the print job to completion. If the server prints to file then the file is opened for the user (in a new window)

Parameters:
Name Type Description
contentType ContentType

enum type of content given (html snippet, url)

content string

the content - a url, html snippet or complete html

htmlPrintSettings object

the html settings to use such as headers and footers, device settings (printer to use, copies etc) are taken from this static

fnDone function

function to call when printing complete (and output returned), arg is null on no error, else error message.

fnProgress function

function to call when job status is updated

data any

object to give pass to fnProgress

View Source meadco-scriptxprint.js, line 2023

  • true if a print was started (otherwise an error will be thrown)
boolean

# static printPdf(document, pdfPrintSettings, fnDone, fnProgress, data) → {boolean}

Post a request to the server to print some html and monitor the print job to completion. If the server prints to file then the file is opened for the user (in a new window)

Parameters:
Name Type Description
document string

full url to the pdf document to be printed

pdfPrintSettings object

the settings to use such as rotation, scaling. device settings (printer to use, copies etc) are taken from this static

fnDone function

function to call when printing complete (and output returned), arg is null on no error, else error message.

fnProgress function

function to call when job status is updated

data any

object to give pass to fnProgress

View Source meadco-scriptxprint.js, line 2061

  • true if a print was started (otherwise an error will be thrown)
boolean

# static removePrinterConnection(sShareName)

Add a printer for the user. The printer driver must already be available.

Parameters:
Name Type Description
sShareName any

View Source meadco-scriptxprint.js, line 1972

# static removePrinterConnectionAsync(sShareName, onSuccess, onFail)

Add a printer for the user. The printer driver must already be available.

Parameters:
Name Type Description
sShareName any
onSuccess any
onFail any

View Source meadco-scriptxprint.js, line 1996

# static reportError(errorTxt)

'derived' classes call this function to report errors, will either throw or report depending on value of onErrorAction.

Parameters:
Name Type Description
errorTxt string

the error text to display

View Source meadco-scriptxprint.js, line 2107

# static reportFeatureNotImplemented(featureDescription)

overridable function for reporting an implementation isnt available. 'derived' classes call this function to report functions that are not yet implemented.

Parameters:
Name Type Description
featureDescription string

descriptn of the feature that isnt available

// overload cloud print library report error
MeadCo.ScriptX.Print.reportFeatureNotImplemented = function (featureDescription) {
  app.Messages.PrintErrorBox(featureDescription + " is not available yet with the ScriptX.Services.\n\nThis feature will be implemented soon.");
}

View Source meadco-scriptxprint.js, line 2147

# static reportServerError(errorTxt)

overridable function for reporting an error. 'derived' classes call this function to report errors.

Parameters:
Name Type Description
errorTxt string

the error text to display

// overload cloud print library report error
MeadCo.ScriptX.Print.reportServerError = function (errorTxt) {
   app.Messages.PrintErrorBox(errorTxt);
}

View Source meadco-scriptxprint.js, line 2128

# static requestHtmlPreview(contentType, content, htmlPrintSettings, fnDone, fnReady)

Post a request to the server to generate a preview. When ready the url from which the preview can be downloaded is passed to the fnReady function.

Parameters:
Name Type Description
contentType ContentType

enum type of content given (html snippet, url)

content string

the content - a url, html snippet or complete html

htmlPrintSettings object

the html settings to use such as headers and footers, device settings (printer to use, copies etc) are taken from this static

fnDone function

function to call when processing is complete arg is null on no error, else error message.

fnReady function

function to call when the preview is available to download

View Source meadco-scriptxprint.js, line 2040

# static serviceDescription() → {ServiceDescriptionObject}

Obtain the description of the service provided by the server

View Source meadco-scriptxprint.js, line 1882

serviceDescription

ServiceDescriptionObject

# static serviceDescriptionAsync(resolve, reject)

Obtain the description of the service provided by the server

Parameters:
Name Type Description
resolve function

function to call on success

reject function

function to call on failure

View Source meadco-scriptxprint.js, line 1901

# static serviceVersion() → {VersionObject}

Get the version of the service connected to.

View Source meadco-scriptxprint.js, line 1728

the version

VersionObject

# static serviceVersionAsync(resolve, reject)

Get the version of the service connected to.

Parameters:
Name Type Description
resolve function

function to call on success

reject function

function to call on failure

View Source meadco-scriptxprint.js, line 1739

# static useAttributes()

search for processing attibutes for connection and subscription/license and process them. The attibutes can be on any element. This function is called automatically by factory emulation and licensing emulation scripts so does not usually need to be called by document script.

Please note synchronous AJAX calls are deprecated in all browsers but may be useful to "quick start" use of older code. It is recommended that code is moved to using asynchronous calls as soon as practical. The MeadCoScriptXJS library can assist with this as it delivers promise rather than callback based code.

View Source meadco-scriptxprint.js, line 1777

Example
<!-- an example connection to an On Premise server for ScriptX.Services -->
<script src="lib/meadco-scriptxservicesprintUI.min.js" 
     data-meadco-server="https://app.corpservices/" 
     data-meadco-subscription="" data-meadco-syncinit="false">
</script>;

<!-- an example connection to ScriptX.Services for Windows PC -->
<script src="lib/meadco-scriptxservicesUI.min.js"
     data-meadco-server="http://127.0.0.1:41191" 
     data-meadco-license="{6BC6808B-D645-40B6-AE80-E9D0825797EF}" 
     data-meadco-syncinit="false" 
     data-meadco-license-path="warehouse"
     data-meadco-license-revision="3">
</script>

data-meadco-server value is the root url, api/v1/printhtml, api/v1/licensing will be added by the library
data-meadco-syncinit default is true for synchronous calls to the server, value 'false' to use asynchronous calls to the server

data-meadco-subscription present => cloud/on premise service, value is the subscription GUID
data-meadco-license present => for Windows PC service, value is the license GUID

If data-meadco-license is present then the following additional attributes can be used:

data-meadco-license-revision, value is the revision number of the license
data-meadco-license-path, value is the path to the license file (sxlic.mlf). A value of "warehouse" will cause the license to be downloaded from MeadCo's License Warehouse
data-meadco-reporterror, default is "true", value "false" suppresses error messages during the initial connection to the service (only)

# static waitForSpoolingComplete(iTimeout, fnComplete)

Start (asynchronous) monitor to observe until no more job spooling/waiting at the server then call the given callback function

Parameters:
Name Type Description
iTimeout int

wait until complete or timeout (in ms) -1 => infinite

fnComplete function

callback function, arg is true if all jobs complete

View Source meadco-scriptxprint.js, line 2232

Type Definitions

# AccessControl

Provide authorisation details to access protected content.

Properties:
Name Type Description
cookie string

The authorisation cookie in the form name=value|name2=value2

View Source meadco-scriptxprint.js, line 107

number

# CollateOptions

Enum to describe the collation option when printing

Properties:
Name Type Description
DEFAULT number

0 use the default at the print server

TRUE number

1 collate pages when printing

FALSE number

2 do not collate pages

View Source meadco-scriptxprint.js, line 594

number

# ContentType

Enum for type of content being posted to printHtml API

Properties:
Name Type Description
URL number

1 the url will be downloaded and printed

HTML number

2 the passed string is assumed to be a complete html document .. ..

INNERHTML number

4 the passed string is a complete html document but missing the html tags

STRING number

8 the passed string is assumed to contain no html but may contain other language such as ZPL (for direct printing)

View Source meadco-scriptxprint.js, line 480

# DeviceSettingsObject

Information about and the settings to use with an output printing device See also: https://www.meadroid.com/Developers/KnowledgeBank/TechnicalReference/ScriptXServices/WebServiceAPIReference/PrintHtml/deviceinfoGET

Properties:
Name Type Description
printerName string

The name of the printer

printToFileName string

The name of a the file to send print output to (for Windows PC and )

paperSizeName string

The descriptive name of the papersize, e.g. "A4"

paperSourceName string

The descriptive name of the paper source, e.g. "Upper tray"

collate CollateOptions

The collation to use when printing

copies number

The number of copies to print

duplex DuplexOptions

The dulex printing option

units MeasurementUnits

Measurement units for papersize and margins

paperPageSize PageSize

The size of the paper (in requested units)

unprintableMargins Margins

The margin that cannot be printed in (in requested units)

status number

Status code for the status of the device. Note this is not reliable, it is the cached return from the first server enquiry only.

port string

Printer connection port name/description

attributes number

Printer attributes

serverName string

Name of the server to which the printer is connected

shareName string

Name of the share

location string

description of the location of the printer

isLocal boolean

true if the printer is local to the server

isNetwork boolean

true if the server is on the network

isShared boolean

true if the printer is shared

isDefault boolean

true if this is the default printer on the service

bins Array.<string>

Array of the names of the available paper sources

forms Array.<string>

Array of the names of the avbailable paper sizes

View Source meadco-scriptxprint.js, line 76

number

# DuplexOptions

Enum to describe the duplex print option to use when printing

Properties:
Name Type Description
DEFAULT number

0 use the default at the print server

SIMPLEX number

1

VERTICAL number

2

HORIZONTAL number

3

View Source meadco-scriptxprint.js, line 611

number

# ErrorAction

Enum for required behaviour when an error occurs.

Properties:
Name Type Description
REPORT number

1 Call MeadCo.ScriptX.Print.reportServerError(errMsg)

THROW number

2 throw an error : throw errMsg

View Source meadco-scriptxprint.js, line 507

# Margins

Describe the margins within which to print.

Properties:
Name Type Description
left number

left margin in requested units

top number

top margin in requested units

right number

right margin in requested units

bottom number

bottom margin in requested units

View Source meadco-scriptxprint.js, line 64

number

# MeasurementUnits

Enum to describe the units used on measurements. Please be aware that (sadly) these enum values do not match
the values by the MeadCo ScriptX COM Servers. Please use MeadCo.ScriptX.MeasurementUnits (declared in MeadCoScriptJS) for compatibility

Properties:
Name Type Description
DEFAULT number

0 use the default at the print server

INCHES number

1

MM number

2 millimeters

View Source meadco-scriptxprint.js, line 36

# PageSize

Describe the size of a page by its width and height.

Properties:
Name Type Description
width number

width of paper in requested units

height number

height of paper in requested units

View Source meadco-scriptxprint.js, line 54

number

# PrintStatus

Enum for status code returned to print progress callbacks

Properties:
Name Type Description
NOTSTARTED number

0

QUEUED number

1

STARTING number

2

DOWNLOADING number

3

DOWNLOADED number

4

PRINTING number

5

COMPLETED number

6

PAUSED number

7

PRINTPDF number

8

ERROR number

1

ABANDONED number

2

View Source meadco-scriptxprint.js, line 558

number

# ServiceClasses

Enum for the class of service connected to.

Properties:
Name Type Description
CLOUD number

1 MeadCo Cloud Service

ONPREMISE number

2 ScriptX.Services for On Premise Devices

WINDOWSPC number

3 ScriptX.Services for Windows PC

View Source meadco-scriptxprint.js, line 523

# ServiceDescriptionObject

Information about the service that is connected to - version detail and facilities available See also: https://www.meadroid.com/Developers/KnowledgeBank/TechnicalReference/ScriptXServices/WebServiceAPIReference/ServiceDescription/GET

Properties:
Name Type Description
serviceClass ServiceClasses

the class of the service; cloud, onpremise, pc

currentAPIVersion string

the latest version implemented (eg 'v1' or 'v2' etc)

serviceVersion VersionObject

implementation version of the service

serverVersion VersionObject

The version of ScriptX Server used by the service

serviceUpgrade VersionObject

The latest version of the service that is available and later than ServiceVersion/me

availablePrinters Array.<string>

Array of the names of the available printers

printHTML boolean

Printing of HTML is supported

printPDF boolean

Printing of PDF documents is supported

printDIRECT boolean

Direct printing to a print device is supported

View Source meadco-scriptxprint.js, line 540

# VersionObject

Description of a code version. Semver is used

Properties:
Name Type Description
major int

The major version

minor int

The minor version

build int

The patch/hotfix version

revision int

Internal revisions of a build/patch/hotfix

majorRevision int

ignore

minorRevision int

ignore

View Source meadco-scriptxprint.js, line 118