MeadCo's ScriptX :: Printing HTML Documents or Reports

This discussion assumes that you are familiar with the basic principles of controlling printing with ScriptX.

In the 'classic' usage of ScriptX to provide an enhanced printing experience of HTML documents in Internet Explorer, the printing UI is included in the page to be printed. This is the approach taken in the standard ScriptX samples; the HTML page to be printed is displayed to the user and includes the ScriptX object and a 'print' button. When the button is clicked, unwanted content is hidden using a CSS stylesheet for the print media and then the displayed HTML document printed.

A common alternative requirement is to provide either:

The latter technique is illustrated here: after choosing the customisation options, the report is printed. This requires the downloading of the customised report and automatic printing - the user has already clicked a 'print report' button, they will not wish to complete another dialog.

There are many ways in which the above requirement can be implemented; this sample implements many of them - one approach may be more appropriate in a particular usage scenario than another or techniques from the different approaches may be combined.

TIP: Of the available approaches, using the PrintHTML or PrintHTMLEx APIs should be given strong consideration. These are licensed functions that provide full queue processing, including disconnected queues. Using the queue management provided by ScriptX is more reliable than techniques that rely upon loading content into frames or child windows and then automatically navigating the frame/window to the next report.

Rather than implement a single 'monster' sample, each technique is implemented on its own - each implementation provides for simple customisation of the report by entry of a name and the printing of the report.

Please use View source from the edit menu in order to inspect the various techniques used here.

Most of these samples use the free subset of ScriptX printing features; licensed features are demonstrated if you wish to do so, this will require you accept the license for this web site.

Print preview

The ability to preview the HTML document to be printed is not provided in any of these approaches.

Self printing in a frame/window

  1. The report is loaded into a hidden (i)frame and it prints itself (the frame).

View Sample.

  1. The report is loaded into a new window, it prints itself and then closes itself.

View Sample.

Printing frame content to enabled shared parameters

In the above samples, the document to be printed carries the MeadCo ScriptX object(s) and print themselves - each report is able to configure printing to its own requirements. In the majority of cases this is sufficient. However, in complex printing scenarios with customisation of many of the printing parameters, the above techniques require that all the print options are passed into the document to be printed. This may include required headers and footers, orientation, margins and the printer to use and so on. Where such requirements are common across a number of reports and/or passing parameters to the report is burdensome, ScriptX can be used in the 'parent' document:

  1. The report is loaded into a hidden (i)frame, the parent document prints the frame when it has loaded.

View Sample. (This sample uses a license which you will need to accept).

NOTE: The technique of loading the report into a new window is not available here because ScriptX cannot print 'across windows', i.e. a ScriptX object in one window cannot cause or control the printing of the content in another window (even if they host content from the same domain).

Queuing/Batch Printing

Each of the above approaches could also be used where a menu of reports is provided and the user will select an individual report for printing. What about when the user may choose multiple reports for printing as a 'batch'?

Two techniques may be used:

  1. Use a script (javascript) based queue with the ScriptX free subset (this emulates some of the behaviour of the printHtml method - see below).

View Sample using (i)Frame.

View Sample that uses a new (modal) window for printing.

  1. Leverage the (licensed) ScriptX PrintHTML method.

This is the final sample. The above two samples use the free subset of ScriptX but the use of licensed features allows for a little more finesse in the implementation; no ugly modal windows and the user can browse away from the report menu page leaving a background process to download and print the reports. The use of the licensed features also allows simpler script for the setting of print parameters such as headers and footers and so on.

View Sample.