Licensed Use :: Using WaitForSpoolingComplete with ScriptX.Services

Activity log  ::  

Asynchronous Printing

All printing with ScriptX is asynchronous.

With ScriptX.Services requests are sent using the http: protocol to a server that processes the request and performs the print - commonly known as AJAX calls to a REST api. This processing is asynchronous.

This sample assumes that the  MeadCoScriptXJS and  MeadCo ScriptX.Services print client modules libraries are in use to enable the same code to be written for both Add-on (Internet Explorer) and ScriptX.Services (any evergreen browser). The sample illustrates the changes that must be made to older code that worked with the Add-on only to support use in any browser.

Each of the functions Print, PrintHTML and BatchPrintPDF will return immediately after the print request has been started and/or queued with the print occuring at the ScriptX.Services server. The browser remains responsive and so the user can close the tab/window while the print is in progress.

Unlike with the Add-on, closing a tab/window does not cause the print to be abandoned - the print will continue and no warnings will be given to the user.

Print to file

If a print is being performed to file for download by the client device and the clicnt browser tab/window is closed then the print will complete at the server but will be uncollected and so 'lost'.

OwnQueue not an exception

The use of OwnQueue() with ScriptX.Services is a no-op as, to all intents and purposes all printing occurs in a separate 'process'.

Use printer:

Default behaviour

These actions illustrate the behaviour of ScriptX printing the current document (i.e. the ubiquitous factory.printing.Print() api) or a remote document (i.e. the factory.printing.PrintHTML() api) without any script code to wait for printing to complete.

Navigate now

WaitForSpoolingComplete

The ScriptX.Add-on WaitForSpoolingComplete function enables synchronous javascript code to be written so that actions can be taken safely once all printing has completed.

For example navigate to another page or close the current window:

// Queue all of the documents in the array for printing, wait for printing
// to be spooled to the printer and then redirect to the given url
function PrintDocumentsAndClose(docUrls,afterPrintRedirect) {
    docUrls.forEach(function(doc) {
        log("Request print of: " + doc);
        MeadCo.ScriptX.Printing.PrintHTML(doc, false);
    });
    MeadCo.ScriptX.Printing.WaitForSpoolingComplete();
    window.location.href = afterPrintRedirect;
}

WaitForSpoolingComplete also enables a busy UI to be implemented very easily. For example, a progress indicator can be shown and hidden:

// a simple show a busy indicator while printing.
function ShowPrintBusy() {
    $("#printBusy").show();
    MeadCo.ScriptX.Printing.WaitForSpoolingComplete();
    $("#printBusy").hide();
}

The code illustrated above will not work as expected with ScriptX.Services.

MeadCo.ScriptX.Printing.WaitForSpoolingComplete() is implemented in javascript but it will return immediately. It is not possible to write blocking functions in javascript that can monitor asynchronmous processes.

Making WaitForSpoolingComplete work with ScriptX.Services

The code updates required are reasonably minimal. Instead of using MeadCo.ScriptX.Printing.WaitForSpoolingComplete() use MeadCo.ScriptX.WaitForSpoolingComplete() from the  MeadCoScriptXJS library instead. This function returns a promise:

// Queue all of the documents in the array for printing, wait for printing
// to be spooled to the printer and then redirect to the given url
function PrintDocumentsAndClose(docUrls,afterPrintRedirect) {
    docUrls.forEach(function(doc) {
        log("Request print of: " + doc);
        MeadCo.ScriptX.Printing.PrintHTML(doc, false);
    });
    MeadCo.ScriptX.WaitForSpoolingComplete().then(function() {
        window.location.href = afterPrintRedirect;
    });
}

A busy UI is also simple to implement by extending the original implementation:

// a simple show a busy indicator while printing.
function ShowPrintBusy() {
    $("#printBusy").show();
    MeadCo.ScriptX.WaitForSpoolingComplete().then(function() {
        $("#printBusy").hide();
    }).catch(function() {
        $("#printBusy").hide();
    });
}

Note that there are 'cascading' consequences to there being no true blocking but asynchronous function. If you have code that calls a similar function to ShowPrintBusy() but that code assumes that ShowPrintBusy() will not return until printing is complete then you will need to add a callback argument. For example:

// a simple show a busy indicator while printing and then call a function when print has completed.
function ShowPrintBusy(fnCallBack) {   
    $("#printBusy").show();
    MeadCo.ScriptX.WaitForSpoolingComplete().then(function() {
        $("#printBusy").hide();
        fnCallBack();
    }).catch(function() {
        $("#printBusy").hide();
    });
}

In these samples we use this technique but also show a dialog to disable any on page user interface.

Print Dialogs in ScriptX.Services

Emulations in javascript of the system Pagesetup and Print dialogs are provided by the  MeadCo ScriptX.Services print client modules library. This library is used by  MeadCoScriptXJS to implement prompted printing. However, these functions are asynchronous so the return value (i.e. did the user elect to print) is not available.

A small code change is required.

From:

if ( MeadCo.ScriptX.PrintPage(true) ) {
    ShowPrintBusy();
}

To:

MeadCo.ScriptX.PrintPage2().then(function(bAccepted) {
    ShowPrintBusy();
});

Same code everywhere

The code changes above will also work with the Add-on - the  MeadCoScriptXJS library hides the differences between implementations.

Behaviour with WaitForSpoolingComplete

These actions illustrate the behaviour of ScriptX when WaitForSpoolingComplete is used and so code waits to take another action.

Navigate now

Some long content to force a longer render time.

New Enterprise improvements coming to IE11 on Windows 7 and 8.1

In Windows 10 version 1511, we announced a number of improvements to our collection of Enterprise Mode tools, designed to help customers upgrade more easily to Internet Explorer 11. These tools include a new v.2 Enterprise Mode XML schema, which is designed to be simpler, cleaner, more scalable, and to help ease list management. We also updated the Enterprise Mode Site List Manager tool, allowing you to import an existing v.1 XML file and automatically convert it to the v.2 XML schema. We added support for HTTP ports, and also introduced a new about:compat page in Microsoft Edge and Internet Explorer 11 to help customers better manage their Enterprise Mode Site List.

To provide a stable environment where compatibility is a top priority, our goal is to keep Internet Explorer 11 consistent, no matter what device or platform you use it on. Today, we are excited to announce that many of these improvements are now available for Internet Explorer 11 on Windows 7, Windows 8.1 and Windows 10 (version 1507). These improvements are included in today’s cumulative updates to Windows.

Read more at Edge Dev Blog

Turn on Enterprise Mode and use a site list

From: Microsft Technet

Applies to:

Before you can use a site list with Enterprise Mode, you need to turn the functionality on and set up the system for centralized control. By allowing centralized control, you can create one global list of websites that render using Enterprise Mode. Approximately 65 seconds after Internet Explorer 11 starts, it looks for a properly formatted site list. If a new site list if found, with a different version number than the active list, IE11 loads and uses the newer version. After the initial check, IE11 won’t look for an updated list again until you restart the browser.

Note
We recommend that you store and download your website list from a secure web sever (https://), to help protect against data tampering. After the list is downloaded, it's stored locally on your employee’s computers so if the centralized file location is unavailable, they can still use Enterprise Mode.

To turn on Enterprise Mode using Group Policy

  1. Open your Group Policy editor and go to the Administrative Templates\Windows Components\Internet Explorer\Use the Enterprise Mode IE website list setting.

    Turning this setting on also requires you to create and store a site list. For more information about creating your site list, see the Use the Enterprise Mode Site List Manager topics.

    local group policy editor for using a site list

  2. Click Enabled, and then in the Options area, type the location to your site list.

    To turn on Enterprise Mode using the registry

  3. For only the local user: Open a registry editor, like regedit.exe and go to HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode.

    -OR-

    For all users on the device: Open a registry editor, like regedit.exe and go to HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode.

  4. Edit the SiteList registry key to point to where you want to keep your Enterprise Mode site list file. For example:

    enterprise mode with site list in the registry

    • HTTP location: "SiteList"="http://localhost:8080/sites.xml"

    • Local network:"SiteList"="\\network\shares\sites.xml"

    • Local file:"SiteList"="file:///c:\\Users\\<user>\\Documents\\testList.xml"

    All of your managed devices must have access to this location if you want them to be able to access and use Enterprise Mode and your site list. For information about how to create and use an Enterprise Mode site list, see Use the Enterprise Mode Site List Manager.

Turn on Enterprise Mode and use a site list

From: Microsft Technet

Applies to:

Before you can use a site list with Enterprise Mode, you need to turn the functionality on and set up the system for centralized control. By allowing centralized control, you can create one global list of websites that render using Enterprise Mode. Approximately 65 seconds after Internet Explorer 11 starts, it looks for a properly formatted site list. If a new site list if found, with a different version number than the active list, IE11 loads and uses the newer version. After the initial check, IE11 won’t look for an updated list again until you restart the browser.

Note
We recommend that you store and download your website list from a secure web sever (https://), to help protect against data tampering. After the list is downloaded, it's stored locally on your employee’s computers so if the centralized file location is unavailable, they can still use Enterprise Mode.

To turn on Enterprise Mode using Group Policy

  1. Open your Group Policy editor and go to the Administrative Templates\Windows Components\Internet Explorer\Use the Enterprise Mode IE website list setting.

    Turning this setting on also requires you to create and store a site list. For more information about creating your site list, see the Use the Enterprise Mode Site List Manager topics.

    local group policy editor for using a site list

  2. Click Enabled, and then in the Options area, type the location to your site list.

    To turn on Enterprise Mode using the registry

  3. For only the local user: Open a registry editor, like regedit.exe and go to HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode.

    -OR-

    For all users on the device: Open a registry editor, like regedit.exe and go to HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode.

  4. Edit the SiteList registry key to point to where you want to keep your Enterprise Mode site list file. For example:

    enterprise mode with site list in the registry

    • HTTP location: "SiteList"="http://localhost:8080/sites.xml"

    • Local network:"SiteList"="\\network\shares\sites.xml"

    • Local file:"SiteList"="file:///c:\\Users\\<user>\\Documents\\testList.xml"

    All of your managed devices must have access to this location if you want them to be able to access and use Enterprise Mode and your site list. For information about how to create and use an Enterprise Mode site list, see Use the Enterprise Mode Site List Manager.

Turn on Enterprise Mode and use a site list

From: Microsft Technet

Applies to:

Before you can use a site list with Enterprise Mode, you need to turn the functionality on and set up the system for centralized control. By allowing centralized control, you can create one global list of websites that render using Enterprise Mode. Approximately 65 seconds after Internet Explorer 11 starts, it looks for a properly formatted site list. If a new site list if found, with a different version number than the active list, IE11 loads and uses the newer version. After the initial check, IE11 won’t look for an updated list again until you restart the browser.

Note
We recommend that you store and download your website list from a secure web sever (https://), to help protect against data tampering. After the list is downloaded, it's stored locally on your employee’s computers so if the centralized file location is unavailable, they can still use Enterprise Mode.

To turn on Enterprise Mode using Group Policy

  1. Open your Group Policy editor and go to the Administrative Templates\Windows Components\Internet Explorer\Use the Enterprise Mode IE website list setting.

    Turning this setting on also requires you to create and store a site list. For more information about creating your site list, see the Use the Enterprise Mode Site List Manager topics.

    local group policy editor for using a site list

  2. Click Enabled, and then in the Options area, type the location to your site list.

    To turn on Enterprise Mode using the registry

  3. For only the local user: Open a registry editor, like regedit.exe and go to HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode.

    -OR-

    For all users on the device: Open a registry editor, like regedit.exe and go to HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode.

  4. Edit the SiteList registry key to point to where you want to keep your Enterprise Mode site list file. For example:

    enterprise mode with site list in the registry

    • HTTP location: "SiteList"="http://localhost:8080/sites.xml"

    • Local network:"SiteList"="\\network\shares\sites.xml"

    • Local file:"SiteList"="file:///c:\\Users\\<user>\\Documents\\testList.xml"

    All of your managed devices must have access to this location if you want them to be able to access and use Enterprise Mode and your site list. For information about how to create and use an Enterprise Mode site list, see Use the Enterprise Mode Site List Manager.

Turn on Enterprise Mode and use a site list

From: Microsft Technet

Applies to:

Before you can use a site list with Enterprise Mode, you need to turn the functionality on and set up the system for centralized control. By allowing centralized control, you can create one global list of websites that render using Enterprise Mode. Approximately 65 seconds after Internet Explorer 11 starts, it looks for a properly formatted site list. If a new site list if found, with a different version number than the active list, IE11 loads and uses the newer version. After the initial check, IE11 won’t look for an updated list again until you restart the browser.

Note
We recommend that you store and download your website list from a secure web sever (https://), to help protect against data tampering. After the list is downloaded, it's stored locally on your employee’s computers so if the centralized file location is unavailable, they can still use Enterprise Mode.

To turn on Enterprise Mode using Group Policy

  1. Open your Group Policy editor and go to the Administrative Templates\Windows Components\Internet Explorer\Use the Enterprise Mode IE website list setting.

    Turning this setting on also requires you to create and store a site list. For more information about creating your site list, see the Use the Enterprise Mode Site List Manager topics.

    local group policy editor for using a site list

  2. Click Enabled, and then in the Options area, type the location to your site list.

    To turn on Enterprise Mode using the registry

  3. For only the local user: Open a registry editor, like regedit.exe and go to HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode.

    -OR-

    For all users on the device: Open a registry editor, like regedit.exe and go to HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode.

  4. Edit the SiteList registry key to point to where you want to keep your Enterprise Mode site list file. For example:

    enterprise mode with site list in the registry

    • HTTP location: "SiteList"="http://localhost:8080/sites.xml"

    • Local network:"SiteList"="\\network\shares\sites.xml"

    • Local file:"SiteList"="file:///c:\\Users\\<user>\\Documents\\testList.xml"

    All of your managed devices must have access to this location if you want them to be able to access and use Enterprise Mode and your site list. For information about how to create and use an Enterprise Mode site list, see Use the Enterprise Mode Site List Manager.

Turn on Enterprise Mode and use a site list

From: Microsft Technet

Applies to:

Before you can use a site list with Enterprise Mode, you need to turn the functionality on and set up the system for centralized control. By allowing centralized control, you can create one global list of websites that render using Enterprise Mode. Approximately 65 seconds after Internet Explorer 11 starts, it looks for a properly formatted site list. If a new site list if found, with a different version number than the active list, IE11 loads and uses the newer version. After the initial check, IE11 won’t look for an updated list again until you restart the browser.

Note
We recommend that you store and download your website list from a secure web sever (https://), to help protect against data tampering. After the list is downloaded, it's stored locally on your employee’s computers so if the centralized file location is unavailable, they can still use Enterprise Mode.

To turn on Enterprise Mode using Group Policy

  1. Open your Group Policy editor and go to the Administrative Templates\Windows Components\Internet Explorer\Use the Enterprise Mode IE website list setting.

    Turning this setting on also requires you to create and store a site list. For more information about creating your site list, see the Use the Enterprise Mode Site List Manager topics.

    local group policy editor for using a site list

  2. Click Enabled, and then in the Options area, type the location to your site list.

    To turn on Enterprise Mode using the registry

  3. For only the local user: Open a registry editor, like regedit.exe and go to HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode.

    -OR-

    For all users on the device: Open a registry editor, like regedit.exe and go to HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode.

  4. Edit the SiteList registry key to point to where you want to keep your Enterprise Mode site list file. For example:

    enterprise mode with site list in the registry

    • HTTP location: "SiteList"="http://localhost:8080/sites.xml"

    • Local network:"SiteList"="\\network\shares\sites.xml"

    • Local file:"SiteList"="file:///c:\\Users\\<user>\\Documents\\testList.xml"

    All of your managed devices must have access to this location if you want them to be able to access and use Enterprise Mode and your site list. For information about how to create and use an Enterprise Mode site list, see Use the Enterprise Mode Site List Manager.