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 users 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 will be available in a number of configurations, including on premise versions as required when confidential information is being printed.

The client

You can roll your own client to call the Web API or leverage the investment we have made in a javascript library for accessing the service.

This sample provides an introduction to adding the use of the ScriptX.Services.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 'Download to PDF' button. The 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.

To show that we arent cheating and using a pre-prepared file for download this sample includes some form fields so you can customise the print. Also note that the date and time on the PDF 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">
        .addEventListener("click",function(event) {
            console.log("Print button clicked");

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. There is no 'pre-deployment' or deployment or installation step required as with the ScriptX add-on for Internet Explorer.

The MeadCo ScriptX.Services modules are available for download from  Github.

Add these javascript modules to the page:

<script src="~/Scripts/jquery-3.1.1.js"></script>
<script src="/scripts/MeadCo.ScriptX/core.js"></script>
<script src="/scripts/MeadCo.ScriptX/scriptxprint.js"></script>
<script src="/scripts/MeadCo.ScriptX/scriptxprinthtml.js"></script>

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

The sample code above has listed out each individual file for illustration. Your environment workflow will enable packaging these files as desired.

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

A subscription identifier is always required as, typically, the ScriptX.Services server will be available at a different url to the server from which the document requesting the print originated and will therefore be subject to cross origin restrictions on scripting. The server will allow calls from origins with a valid identifier.

The subscription at the server will also define the features available - for example basic (margins, headers, footers etc) or advanced (printer selection, print properties such as papersize etc).

Define print parameters and print

Finally, we can put everything together to print the page to a PDF document. The ScriptX.Services modules will take care of the response from the server will be a file and will download the file when it is ready.


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