# Wednesday, 03 August 2005

Howto: Printing html documents/reports 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:

  • a menu of available reports (where clicking a link results in the chosen report being printed) or
  • some set of options by which a particular report may be customised.

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.  [via MeadCo's ScriptX Sample - Printing Reports]

Personally I prefer the iframe based solutions or use printhtml().

#    Comments [0] |
# Tuesday, 02 August 2005

How to print html documents or reports with custom headers and footers in Internet Explorer.

The headers and footers printed when a web page is printed in Internet Explorer is defined in the IE Page Setup dialog - a number of meta commands are available for including page numbers and dates etc - but then you knew that.

When printing an html document or report in a corporate environment or on specialist pages from web sites (e.g. printing a post card) it can be desirable to use headers/footers appropriate to the report or remove the headers and footers altogether, but only for the particular report/page.

ScriptX is an ActiveX control from MeadCo that provides this control, and much more. For just controlling the headers and footers it is free.

1. Include the ScriptX object on the page, either in the <head> or <body> sections of the document:

<!-- MeadCo ScriptX Control --> 
<object id="factory" style="display:none" viewastext
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=6,2,433,14">
</object>

(The installation cab file can be downloaded from your own servers).

2. Initialise the required print parameters in the onload event with a little bit of javascript:

<script language="jscript">
function initPrinting() {
   factory.printing.header = "ScriptX Printing";
   factory.printing.footer = "";
}
</script>
<body onload="initPrinting()">
...
</body>
</html>

Now, when the user chooses print (either from the File menu or via some scripted button), the page will be printed with the defined headers. When the user navigates away from the page their default print settings will be restored.

#    Comments [1] |