ScriptX - Controlled and Consistent Print Output
  • Getting started
  • My Account
  • Downloads
  • Features
    • ScriptX.Services
    • ScriptX.Add-on
  • Pricing & Licensing
    • ScriptX.Services
    • ScriptX.Add-on
    • Deployment
  • Case Studies
  • About Us
  • Blog
  • Developers
    • Knowledge Bank 
      • ‘How To’ Guides
      • Technical Reference
      • Samples
    • About ScriptX.Services
    • Developer Downloads
    • Codestore
    • Community
  • Contact
Developers ›  Knowledge Bank ›  How To Guides ›  ScriptX.Services ›  Then To Now ›  Stage 7

WaitForSpoolingComplete()

This walk-through illustrates taking a classic document that has a controlled print experience and works only in Internet Explorer and making it work with ScriptX.Services in any browser on any platform using the minimum amount of development effort and making as few changes as possible (though more changes might be desirable).

Previously : Stage 6 - Preparing for advanced uses

Background

Each of the functions Print, PrintHTML and BatchPrintPDF will return immediately after the print request has been started and/or queued with the print continuing either in the background with ScriptX.Add or with ScriptX.Services at the server.

The browser remains responsive and so the user is able close the tab/window while the print is in progress.

ScriptX.Addon

With ScriptX.Addon, if the window/tab is closed or navigated away from then any print in progress would immediately stop.

So, if a navigation occurs or window/tab is closed while printing with ScriptX.Addon, ScriptX.Addon will pause the action for 5 seconds to allow the print to complete.

If the print is still not complete then the user will be asked if they wish to abandon the print (the window/tab will close) or wait for it to complete before continuing the action. The prompts that appear are clear and concise and can be customised.

ScriptX.Services

No such solution is available to javascript.

The browser beforeunload event can be used to some effect but suffers from the fact that the dialog message is misleading as only a generic message will ever be displayed and there is no way to offer users more sophisticated options other than "stay or leave".

This means there is no satisfactory way to implement the behaviour of ScriptX.Add-on with ScriptX.Services.

There is an extent to which this does not matter as printing is occuring in a separate service and will continue after the navigation or closure of a tab/window.

However, there are occasions where finer control and feedback to the user is worthwhile. For example:

  • A number of jobs have been submitted to the printHtml() API. If the window/tab is closed many prompts may be given to the user to request permission to close the window.
  • Jobs submitted to printHtml() should be verified that they have succeeded and re-submit/report those that fail for some reason.
  • Visually show printing is in progress and the user should wait.
  • Cleanly avoiding an error display if a print is started with ScriptX.Servicees and the window is closed immediately after.

Each of these use cases is handled by the WaitForSpoolingComplete API.

The WaitForSpoolingComplete() API Is emulated with the ScriptX.Services client library but requires an additional argument. To ease the transition the MeadCoScriptXJS library implements a function that returns a promise and can be used with either ScriptX.Addon or ScriptX.Services.

This means this code:

factory.printing.Print(false);
factory.printing.WaitForSpoolingComplete();
self.close();

becomes:

factory.printing.Print(false);
MeadCo.ScriptX.WaitForSpoolingComplete().finally(function() {
    self.close();
})

Or, for a more complete example:

$("#btn-print").click(function () {
    MeadCo.ScriptX.PrintPage2(true).then(function (bStarted) {
        if (bStarted) {
            var $dlg = $("#dlg-busy");

            $dlg.modal("show");
            MeadCo.ScriptX.WaitForSpoolingComplete().finally(function () {
                $dlg.modal("hide");
            });
        }
    });
});

Open your browser (any browser) and go to the address  https://scriptxprintsamples.meadroid.com/ThenToNow/now-stage7

A more extensive discussion of WaitForSpoolingComplete() is available at ScriptX Samples

Next up: Stage 8 - Recommendations for some common issues.
  • Knowledge Bank
  • 'How To' Guides
    • ScriptX.Add-on
      • Introduction
      • Installing ScriptX on client PCs
      • Basic printing with ScriptX
      • Advanced printing features
      • Backwards compatibility
      • How to check if ScriptX is installed
      • MeadCoScriptXJS Library
      • License deployment
      • Client-side printing samples
    • ScriptX.Services
      • Introduction
      • Getting started
      • Maintaining investment in current code
        • Stage 1: Adding UI
        • Stage 2: Printing with ScriptX.Services
        • Stage 3: Summary and review
        • Stage 4: Error reporting
        • Stage 5: Prompted printing
        • Stage 6: Preparing for advanced uses
        • Stage 7: WaitForSpoolingComplete
        • Stage 8: Recommendations for some common issues
      • MeadCoScriptXJS Library
      • Printing with the API
      • Installing ScriptX.Services
        • For Windows PC v1
        • For On Premise Devices hosted on Windows Server v1
        • For On Premise Devices hosted on Windows 10 v1
        • Cloud
      • Debugging
      • License deployment
        • For Windows PC
        • For On Premise Devices
      • Samples
        • Configure for Windows PC
        • Configure for On Premise
        • Configure for Cloud
    • Security Manager
      • Deploying a license or revision
  • Technical Reference
    • ScriptX.Add-on
      • factory
        • baseUrl
        • ComponentVersionString
        • IsUniqueIDAvailable
        • OnDocumentComplete
        • relativeUrl
        • ResetUniqueID
        • ScriptXVersion
        • SecurityManagerVersion
        • Shutdown
        • UniqueID
      • printing
        • AddPrinterConnection
        • BatchPrintPDF
        • BatchPrintPDFEx
        • bottomMargin
        • collate
        • copies
        • currentPrinter
        • DefaultPrinter
        • disableUI
        • duplex
        • duplex2
        • EnumJobs
        • EnumPrinters
        • footer
        • GetJobsCount
        • GetMarginMeasure
        • header
        • headerFooterFont
        • IsSpooling
        • IsTemplateSupported
        • leftMargin
        • onafterprint
        • onbeforeprint
        • onbeforeunload
        • onpagesetup
        • onuserpagesetup
        • onuserprint
        • onuserprintpreview
        • orientation
        • OwnQueue
        • pageHeight
        • PageSetup
        • pageWidth
        • paperSize
        • paperSource
        • paperSource2
        • portrait
        • Preview
        • Print
        • printBackground
        • printer
        • PrintHTML
        • PrintHTMLEx
        • PrintPDF
        • PrintSetup
        • printToFileName
        • RemovePrinterConnection
        • rightMargin
        • SetMarginMeasure
        • SetPageRange
        • SetPreviewZoom
        • SetPrintScale
        • Sleep
        • templateURL
        • topMargin
        • TotalPrintPages
        • unprintableBottom
        • unprintableLeft
        • unprintableRight
        • unprintableTop
        • WaitForSpoolingComplete
      • printerControl
        • attributes
        • Bins
        • Forms
        • isLocal
        • isNetwork
        • isShared
        • Jobs
        • location
        • name
        • Pause
        • port
        • Purge
        • Resume
        • serverName
        • shareName
        • status
      • Job
        • Delete
        • Pause
        • Restart
        • Resume
      • enhancedFormatting
        • allFooterHeight
        • allHeaderHeight
        • allPagesFooter
        • allPagesHeader
        • extraFirstFooterHeight
        • extraFirstPageFooter
        • firstFooterHeight
        • firstHeaderHeight
        • firstPageFooter
        • firstPageHeader
        • pageRange
        • printingPass
      • rawPrinting
        • printer
        • printDocument
        • printString
    • ScriptX.Services
      • Web service API
        • Service Description
          • (GET)
        • Licensing
          • licensing (GET)
          • licensing (POST)
          • licensing/ping (GET)
        • PrintHtml
          • settings (GET)
          • deviceinfo (GET)
          • htmlPrintDefaults (GET)
          • print (POST)
          • status (GET)
          • download (GET)
          • canceljob (PUT)
        • PrintPdf
          • print (POST)
          • status (GET)
          • download (GET)
        • PrintDirect
          • print (POST)
    • Security Manager
      • How it works
      • License Expiry
      • Testing for a valid license
      • About the license file (.mlf)
        • LICENSE
        • APPLICENSE
        • TITLE
        • DOMAINS
        • DOMAIN
        • PERMISSION
      • API
        • Apply
        • License
        • result
        • validLicense
  • Articles
    • Dialogs with ScriptX.Services
 
© 2025 Mead & Co Limited. Version: 4.2.8-R.20210726.1 | Privacy Policy
© 2025 Mead & Co Limited. v1.0.2
X

Warning:

This ScriptX.Add-on sample can only be viewed using Internet Explorer.