ScriptX.Services :: An Introduction

ScriptX.Services is the evolution of the 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.

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.

The server

The ScriptX.Services server providing the print Web API is available in a number of configurations including an on premise version for shared services and a version for individual Windows PC.

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 deplopyment 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 there 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/.

The client

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 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",function(event) {
            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 viz. 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/jquery@3.1.1/dist/jquery.min.js"></script>
<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

 For version 1, ScriptX.Services depends on jQuery for ajax and some DOM manipulation services so jQuery must be referenced, and as shown above it should be referenced before ScriptX.Services.

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).

A subscription/license identifier is usually required; the server will allow calls from origins with a valid identifier.

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. The code here assumes that the license is already installed on the client PC.

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.