How to code with ScriptX.Services For On-Premise Devices
This page provides an introduction to using your own ScriptX.Services For On-Premise Devices to print pages from your own web apps.
Your web app does not need to be hosted on the same domain or server as ScriptX.Services. The service API allows calls from any origin - it is assumed therefore that your server is not exposed to the public internet or that you have appropriate security in place.
There is no client installation. ScriptX.Services for On-Premise Devices is a 'one-time' install to a suitable server. Updates to the system are to the single server and client library updates are automatically delivered to client devices: all the advantages of web based delivery.
The disadvantage may be ensuring the abilility to address required printers and also providing sufficient throughput for the number of concurrent print jobs there may be. If printers are centralised and there will not be a high concurrency of print jobs to a server then ScriptX.Services for On-Premise Devices is a compelling solution.
ScriptX.Services for Windows PC
ScriptX.Services for Windows PC must first be installed to each device (only Microsoft Windows Intel x64 PC) and a MeadCo ScriptX Client license deployed. Unlike with ScriptX.Add-on for Internet Explorer this has to be a separate process; it cannot be automated using a .cab based installer that is referenced by and delivered with the page.
However, ScriptX.Sericess for Windows PC enables printing to any printer available to the PC and there will not be through-put issues from concurrent print jobs as by definition the device is "single user".
Please take a look at ScriptX.Services for Windows PC for more details.
To deliver a print experience to your users any page in your app that provides printing of the page must:
- Add code to configure the library,
- Add code to describe required settings such as margins, headers and footers,
- Add a print button or other appropriate UI to your page,
- Connect the print button click even, or appropriate UI event to the ScriptX.Services code using your favourite technique,
A worked example - this page
We'll do things in a slightly different order.
This page has a 'Download to PDF' button, as do other pages on the site. The download is obtained by using Cloud ScriptX.Services to `print` this document to a PDF and then provide the `printed file` as a download.
Working with an on-premise server is just the same, but with an on-premise server the printer may be a physical printer connected to the server so there would be no download for the user.
The UI :: the print button
The button is standard html styled with some Bootstrap css and Font Awesome:
Wire up an event handler
We won't use any library to help us though obviously we could as they all resolve to being an abstraction on the underlying DOM:
At this point we have a button which when clicked writes an information line to the console.
We have a roadmap for ScriptX along which we will add new features and classes of printing. At the moment we only have printing of HTML available but our module structure reflects the fact this will change and we want the changes and additions to re-use code as much as possible.
<script src="/Scripts/jquery-3.1.1.js"></script> <script src="/Scripts/MeadCo.ScriptX/meadco-core.js"></script> <script src="/Scripts/MeadCo.ScriptX/meadco-scriptxprint.js"></script> <script src="/Scripts/MeadCo.ScriptX/meadco-scriptxprinthtml.js"></script>
The sample code above has listed out each individual file for illustration. Your environment workflow will enable packaging these files as desired.
The whole of MeadCo.ScriptX.Print.HTML is now available to the page.
ScriptX.Services Client library dependencies
For version 1, ScriptX.Services client depends on jQuery for ajax and some DOM manipulation services so jQuery must be referenced.
ScriptX.Services client must be configured with the url of the ScriptX.Services server.
or, and in preference use an asynchronous connection to the server with a callback function to be called when the server connection is completed. Asynchronous initialisation is preferred as it does not block the browser UI.
Define print parameters and print
Finally, we can put everything together to print the page to the ScriptX.Services Server default printer.
Complete the form and then print. Your form values will be included on the print.
The print buttons on this page use the MeadCo ScriptX.Services for Cloud to print and deliver the printed output as a PDF file. The code is exactly the same as would be used to ScriptX.Services for On-Premise Devices.
Moving older systems to modern browsers can be a daunting task. Moving code that provided controlled printing with ScriptX.Add-on to ScriptX.Services shouldn't be daunting.
Most code that uses ScriptX.Add-on assumes the presense of an object
To support old code, the following libraries are required:
<script src="/Scripts/jquery-3.1.1.js"></script> <script src="/Scripts/MeadCo.ScriptX/meadco-core.js"></script> <script src="/Scripts/MeadCo.ScriptX/meadco-scriptxprint.js"></script> <script src="/Scripts/MeadCo.ScriptX/meadco-scriptxprinthtml.js"></script> <script data-meadco-subscription="" data-meadco-server="http://<yourlocaldomain>/<yourOnPremServicesAppName>" src="/Scripts/MeadCo.ScriptX/meadco-scriptxfactory.js"> </script> <!-- optional --> <script src="/Scripts/MeadCo.ScriptX/meadco-scriptxlicense.js"></script>
Note that the server and subscription identifier are included as attributes on the <script /> tag and so there is no reason to call MeadCo.ScriptX.Print.HTML.connect(). With this in place the <object /> tags required for ScriptX.Add-on (including MeadCo License Manager) can be replaced with the <script /> tags and a highly significant amount of code will `just work`.
Changes in licensing
With the move to a server based system, the client no longer needs to accept a license. There is no equivalent of the MeadCo Security Manager add-on when using ScriptX.Services for On-Premise devices.
Supporting old and new browsers
If you can get your HTML to work with both old (before Internet Explorer 11) and modern browsers then you can use your current ScriptX code unchanged.
With our ScriptX.Services libraries you can write the code that works seemlessly with both the ScriptX.Add-on and ScriptX.Services.
Include the ScriptX.Services client libraries on the page and they will quietly do nothing when ScriptX.Add-on is available. The result is users with old browsers will be able to print to a printer connected to their workstation, users of modern browsers will be able to print to printers available to the ScriptX.Services server and which ever version of ScriptX, your users will get the same experience with consistent output.
MeadCoJS Library and Asynchronous functions
Many developers have made use of our MeadCoJS Script Library availabe on GitHub MeadCoScriptXJS
. Since v1.4 this library provides a complete encapsulation of using both ScriptX.Add-on and ScriptX.Services from the same code. The library (optionally) uses modern promise based coding (a promise library is
required for Internet Explorer 11) and provides wrappers for implementing asynchronous functions that we provided in ScriptX.Add-on. For example, the ubiquitous
factory.printing.WaitForSpoolingComplete() is implemented albeit with a different function prototype.
However, the library enables writing a single code base for printing which will work when either the Add-on or Services is used within the client browser. The library is used throughout our samples to illustrate this and allows us to write a sample just once.
More samples and illustrations
This has been a quick introduction on how to develop with ScriptX.Services for On-Premise Devices installed on your own servers and deliver controlled and consistent print experiences to your users.
Continue in this section with how to work with ScriptX.Services for On-Premise Devices:
- How to install and configure ScriptX.Services for On-Premise Devices server.
- How to use our samples with your own ScriptX.Services for On-Premise Devices server.
Features and futures
We do not intend to stand-still, read on for our roadmap.