Basic printing with ScriptX
A basic subset of ScriptX client-side printing functionality -- header & footer settings, printed orientation, coarse control of margins and a browser window/frame printing command -- is available at no charge, and is freely distributable.
The basic printing of an HTML document with ScriptX follows a simple pattern:
- Enable 'basic' printing by authoring the MeadCo ScriptX OBJECT tag on the document
- Author the required UI, for example a button which when clicked will print the document
- Develop the script that runs in response to a UI action, such as the button click. The script will set required printing attributes and start the print action
How to enable ‘basic’ printing
A ‘basic’ ScriptX-enabled document is defined as one on which the ScriptX object block appears thus:
<!-- MeadCo ScriptX -->
<object id="factory" style="display:none"
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="http://[your path here]/smsx.cab#Version=8,3,0,4">
</object>
For successful installation and operation the codebase attribute must ‘point’ to the correct location and version number of the smsx.cab file on your servers. That ‘pointer’ path can be relative to the location of the document on which the ScriptX object appears, or it can be fully qualified.
For more details on installation options, please see Installing ScriptX on Client PCs.
Authoring the UI
Obviously this is entirely dependent on particular application requirements but the essentials are always the same; a document element (such as a button) raises an event in response to a user action (such as a click) and a scripted event handler implements the required actions (such as setting print headers and footers and starting the print).
ScriptX is entirely agnostic about how you develop your scripts, for example, you might wish to use jQuery (as we do in the samples) or some other javascript library. For the purposes of illustration, the example below is old fashioned, but simple!
<button onclick="btn_print_onclick()">Print report</button>
Event handling script - formatting printing attributes and printing
A typical function call to set ‘basic’ print formatting and print a top-level document client-side could look like this:
function btn_print_onclick() {
factory.printing.header = "This is MeadCo";
factory.printing.footer = "Printing by ScriptX";
factory.printing.portrait = false;
factory.printing.leftMargin = 1.0;
factory.printing.topMargin = 1.0;
factory.printing.rightMargin = 1.0;
factory.printing.bottomMargin = 1.0;
factory.printing.Print(false);
}
Notice that we call all ScriptX functions by reference to the ID of the on-page ScriptX object - usually ‘factory’.
Notes:
- In your own code, we recommend that you place the ScriptX <OBJECT> elements in the document's <BODY> container.
- Start to script the ScriptX object only when the page is fully loaded i.e. only once the body.onload event has occured.
- You should never call the ScriptX object from in-line script that is run when the document is first parsed. This technique will guarantee inconsistencies in the working of your code because of the timing errors that can result.
- The ‘de-facto’ standard - as started by this documentation - is to use the id ‘factory’ for the ScriptX object. Any id that is desired may be used.
- For simplicity, these documents directly refer to the object via its id rather than using document.getElementById(). Either approach is acceptable.
- If the samples are inspected via View Source it will be seen that the jQuery library is used in the samples, along with a wrapper class to safely access the ScriptX object. The use of jQuery etc is also entirely optional.
- Only one ScriptX object can appear on any one document.
- You can not use CreateObject or new ActiveXObject to create the ScriptX object and ScriptX-enable a page.