2.7.6.121001, 10 December 2018 11:38 AM : © 2018 - Mead & Company Ltd.

ScriptX.Services for Windows PC

Background

ScriptX gives developers consistent control of browser-based printing. ScriptX.Add-on for Internet Explorer is deployed on many millions of client devices worldwide to control the print of billions of documents annually.

ScriptX.Add-on

ScriptX.Add-on for Internet Explorer uses a deep integration with the Internet Explorer UI and custom templates for the Trident Print engine within Internet Explorer. This enables the Internet Explorer engine to be used to paginate the document and render to the print output device.

The add-on needs to be installed on each client PC - a process that in general requires Administrator privileges and for advanced usage requires a license is accepted and installed by each user of Internet Explorer.

To control the print process the developer writes script code to set required properties on and call methods from the add-on to perform printing and other tasks. Typically the add-on was instantiated with the id 'factory' so code such as this is typical:

<!-- MeadCo ScriptX -->
<object id="factory" style="display:none"
  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
  codebase="installers/smsx.cab#Version=8,0,0,56">
</object>
<script type="text/javascript">
function printPage() {
    factory.printing.header = "";
    factory.printing.footer = "";
    factory.printing.paperSize = "A4";
    factory.printing.Print(false); // don't prompt
}
</script>

As well as working within Internet Explorer we developed ScriptX so that it could be used as an HTML print engine for applications and services such as Internet Information Services (IIS).

In other words, the print technology of ScriptX is tried, tested and used over many years to prove its reliability and robustness.

ScriptX.Services Evolution

To support modern browsers on any device with ScriptX.Services we take that technology and deploy it behind a rich  Web API on a local web server that provides the interface between the ScriptX print engine on the PC and the client devices.

The interface accepts a stream of html to print and the settings to use and then passes those onto the print engine which then prints the html with the provided settings such as headers, footers, margins, printer to use, papersize to use and so on.

So, instead of the printing being performed within and by the user's browser, the content to be printed is sent from user's browser to the local web server where it is paginated and rendered to a print device connected to the PC.

Browser support

Supporting customers who have an investment in javascript that works with ScriptX.Add-on for Internet Explorer is very important to us. It will be enough of a challenge to convert HTML content originally authored for IE 7/8 to modern HTML that works in all browsers.

To support customers with current code, we are providing an 'anti-polyfill' that implements an emulation of ScriptX.Add-on in javascript  Github (old techniques into modern browsers rather than the typical polyfill which enables old browsers to use modern techniques). The anti-polyfill will work with both '.factory' based code and with  MeadCoScriptXJS based code.

Our ScriptX.Services client libraries support Internet Explorer 11, Edge, Chrome, Firefox and Safari (and any modern evergreen browser that supports HTML 5 and ECMAScript 5 or later).

ScriptX.Add-on for Internet Explorer continues to be supported for earlier versions of Internet Explorer.

Print functions

ScriptX.Add-on provides three three ways of printing HTML content from the browser. Each of these functions prints a 'snapshot' of the content as currently displayed in the browser. ScriptX.Services supports each print function.

Print the page/document [aka factory.Print()]

To print the page/document means delivering the HTML stream to print from the client device to the server. A javascript module implements capturing the current browser DOM content and then delivers that to the server along with required settings.

A further javascript module implements the behaviour of the ScriptX.Add-on window.factory object, but in javascript. Very familiar looking code can then be written.

  1. Replace the <object id="factory" ... /> element from the ScriptX.Addon with including a javascript module that defines a window.factory object that fully emulates ScriptX.Add-on.

    <script src="/scripts/meadco-core.js"></script>
    <script src="/scripts/meadco-scriptxprint.js"></script>
    <script src="/scripts/meadco-scriptxprinthtml.js"></script>
    <script src="/scripts/meadco-scriptxfactory.js"></script>
    <script src="/scripts/meadco-scriptxprintlicensing.js"></script>
    <script src="/scripts/meadco-secmgr.js"
        data-meadco-license="C4DB5D29-BE52-46B9-9DDF-46A167170F81"
        data-meadco-license-revision="2"
        data-meadco-license-path="warehouse"
        data-meadco-server="http://127.0.0.1:41191">
    </script>
                
  2. The javascript doesnt change:

    <script type="text/javascript">
    function printPage() {                  
        factory.printing.header = "";
        factory.printing.footer = "";
        factory.printing.paperSize = "A4";
        factory.printing.Print(false); // don't prompt
    }
    </script>
    

To be clear; when the 'Print(false)' function executes, the html as displayed on screen is sent to the local web server along with references to required external resources such as style sheets and images (script references are not sent). The html document is then paginated and rendered.

The settings such as header and footer are not sent with each setting of a property. The values are stored in variables on the client and then sent to the server with the stream of html to print.

Print a remote document [aka factory.PrintHtml()]

To print a remote document is simple - send the url to be downloaded and printed to the local web server along with the required settings. In otherwords, instead of the stream to print, just the url. The server then requests the HTML content from the url then it is paginated and rendered.

Print document fragments [aka factory.SetPageRange(); factory.Print()]

The SetPageRange() function sets a flag such that only the content that is selected (either programmatically or by the user) is printed. The requirement for a selection means this is not hugely useful, but the ability to print a fragment of or part of the current html document or even a dynamically generated document fragment without the need to copy it into the DOM is useful.

With ScriptX.Services we can easily do this by taking a snap shot of part of the DOM rather then the whole page DOM when printing the whole document. The html is sent along with references to required external resources such as style sheets and images (script references are not sent). The html is then assembled as a complete document, paginated and rendered.

 Write once

With our ScriptX.Services libraries you can write the code that works seemlessly with both the ScriptX.Add-on and ScriptX.Services. Whichever browser, which ever device, which ever version of ScriptX, your users will get the same experience with consistent output.

To write once, leave the ScriptX.Add-on object on the page and add the script files. In those browseers that support ScriptX.Add-on it will be used, in those browsers that don't the emulation will be used:

<!-- MeadCo ScriptX -->
<object id="secmgr" style="display:none"
  classid="clsid:5445be81-b796-11d2-b931-002018654e2e"
  codebase="installers/smsx.cab#Version=8,0,0,56">
    <param name="GUID" value="{C4DB5D29-BE52-46B9-9DDF-46A167170F81} " />
    <param name="Path" value="sxlic.mlf" />
    <param name="Revision" value="2" />
</object>
<object id="factory" style="display:none"
  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"">
</object>
<script src="/scripts/meadco-core.js"></script>
<script src="/scripts/meadco-scriptxprint.js"></script>
<script src="/scripts/meadco-scriptxprinthtml.js"></script>
<script src="/scripts/meadco-scriptxfactory.js"></script>
<script src="/scripts/meadco-scriptxprintlicensing.js"></script>
<script src="/scripts/meadco-secmgr.js"
    data-meadco-license="C4DB5D29-BE52-46B9-9DDF-46A167170F81"
    data-meadco-license-revision="2"
    data-meadco-license-path="warehouse"
    data-meadco-server="http://127.0.0.1:41191">
</script>
<script type="text/javascript">
function printPage() {
    factory.printing.header = "";
    factory.printing.footer = "";
    factory.printing.paperSize = "A4";
    factory.printing.Print(false); // don't prompt
}
</script>

Modern code

A chance to re-write is always welcome and the very flat properties/methods list of the add-on isn't the design approach that would be taken now.

Our service exposes a rich  Web API for describing the parameters to use on the print and delivering the HTML content to print.

If you are starting new projects now, then you might want to use your preferred library - jQuery, Angular, React, Vue, Axios etc etc to provide the library for calling a REST API and then extract relevant portions from our libraries on  Github for extracting the HTML to  send to the service [Swagger API Specification].

The choice is yours.

Advantages of ScriptX.Services

 Modern browser independence; the host browser and device is not used to to print, print occurs at a server.

 Consistent output whatever the client browser. A single print engine is used at the server so the results will always be the same.

Disadvantages

 We are unable to intercept the browser UI for printing. So, for example Ctrl-P and menu options for printing cannot be redirected to use ScriptX.Services. The browser window.print() method can be overloaded in the usual way with javascript.

 At this time we are using the Internet Explorer 11 Trident Rendering engine in 'edge' mode. This is a highly capabable mode with a high degree of compatibility with modern standards HTML as might be required to be printed but clearly there will be some content that cannot be printed or will appear incorrect if it is not supported by Internet Explorer 11 in standards mode.

How to work with ScriptX.Services for Windows PC

So that's the background on the evolution, read on for how to 'deploy' and use ScriptX.Services for Windows PC.