ScriptX.Services :: An Introduction

ScriptX.Services is the evolution of ScriptX.Add-on for Internet Explorer to provide developers with the tools for ensuring the consistent formatting and appearance of printed output regardless of the user's device or modern browser.

Print service server

Browsers have no extensibilty for printing. So, instead of the printing being performed within and by the user's browser, the content to be printed is sent to a server where it is paginated and rendered to a print device connected to the server. If that print device prints to file (e.g. 'Write to PDF' device is used) then the file can be returned to the user where they can print out the content on their local printer.

ScriptX.Services is available in three configurations:

Whichever ScriptX.Services server is used:

The API is the same enabling the same client code to be used with any configuration.

When using ScriptX.Services for Windows PC, then it must be deployed to the PC first.

There is no automated deployment as there was with ScriptX.Addon. To install ScriptX.Services for Windows PC the user must download and run the installer (.MSI) or have it installed by an organisation's Software Management Services.

If ScriptX.Services for Cloud or for On Premise devices is used then no 'pre-deployment' or deployment or installation step is required.

By default these samples use the  MeadCo Cloud Print service but can be configured to use your own for On-Premise Devices or for Windows PC ScriptX.Services server. To configure use of your own server, use  Settings. Note that if you configure to use your own server then prints will be sent to the default printer.

Your configured server is: https://scriptxservices.meadroid.com/.

Browser hosted code

You can roll your own client code to call the  ScriptX.Services Print API or leverage the investment we have made in a javascript library for accessing the service:  MeadCo ScriptX.Services print client modules .

This sample provides an introduction to adding the use of the ScriptX.Services for printing HTML to your own pages:

  1. Reference the javascript library and dependencies,
  2. Add code to configure the library,
  3. Add code to describe required settings such as margins, headers and footers,
  4. Add a print button to your page,
  5. Connect the print button click event to the ScriptX.Services code using your favourite technique,
  6. Done!

A worked example - this page

We'll do things in a slightly different order.

This page has a 'Print this page' button. When using the cloud service a download is obtained by using the ScriptX.Services server to `print` this document to a PDF and then return the `printed file` as a download. Other services will print to their default printer.

To show that we arent cheating and using a pre-prepared file for download / printing this sample includes some form fields so you can customise the print. Also note that the date and time on the PDF / print will be the time you requested the print.

The UI :: the print button

The button is standard html - in this cased 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:

<script type="text/javascript" defer="true">
    document.getElementById("btn_printPage")
        .addEventListener("click",() => {
            console.log("Print button clicked");
        });
</script>

At this point we have a button which when clicked writes an information line to the console.

Reference the ScriptX.Services javascript modules

The client part of ScriptX.Services is written entirely in javascript and is delivered to client browsers in the usual way with a <script /> tag with src attribute referencing the location of the script.

The MeadCo ScriptX.Services modules are available for download from  Github or can be referenced via a cdn.

For example, add these javascript module links to the page:

<script src="//cdn.jsdelivr.net/npm/scriptxprint-html@1/dist/meadco-scriptxservices.min.js"></script>

The whole of MeadCo.ScriptX.Services.HTML is now available to the page.

ScriptX.Services dependencies

 As of version 1.15, the ScriptX.Services client library has no dependencies on other libraries. It uses the Fetch API for network requests and the browser's native functions for other operations.

The library uses 'static' instances of the namespaced 'classes' and so can be used in a 'functional' style without the need to create instances of the classes. These instances are available as properties of the MeadCo object which is created as the scripts are loaded. As a consequence there is no need to 'import' the classes and the library will work with any framework or library.

Configure ScriptX.Services

ScriptX.Services must be configured with two parameters:

  1. The url of the ScriptX.Services server.
  2. A subscription/license identifier (unless using ScriptX.Services for On-Premise devices).

Licensing ScriptX.Services

  1. For ScriptX.Services for Cloud,  request a subscription.
  2. For ScriptX.Services for Windows PC, you can use the evaluation license {3cfd70e2-f38f-4ab2-95f4-4ce4c1e39497} for testing content delivered from //localhost.

Define print parameters and print

Finally, we can put everything together to print the page. The ScriptX.Services modules will take care of a response from the server that a file (e.g. PDF) will be produced and will download the file when it is ready. In other cases, the print will appear on the default printer.

Done!

Complete the form and then print. Your form values will be included on the print though the value of password will not print.