October 2003
This document applies to ScriptX Printing v6.1.429.14 or later. If you are using an earlier version, please contact MeadCo for an upgrade.
Last updated: 16th September 2003
ScriptX can be used with Microsoft's Internet Information Server» (IIS) and Active Server Pages/ASP.NET to print HTML documents on the server side.
An Active Server Page (ASP or ASP.NET) may handle an HTTP GET or POST request and print a report (a different HTML page) as part of some server-side application logic. In this case, the print-out will take place on the server side and will go to a printer which is physically attached or networked to the server. The browsing user who originated the HTTP request may not ever see the printed output nor know that printing has taken place.
We strongly recommend that the following articles are studied before server side deployment of ScriptX Printing:
The Internet Explorer components are utilised to perform the printing - ScriptX Printing does not contain any actual printing code. Please take note of all the caveats Microsoft place around the use of Office Applications as automation servers. Many of these caveats apply to the use of Internet Explorer. Internet Explorer was developed with the intention of a user sitting in front of it, not as a server service. Since Internet Explorer is an application intended for use by a user rather than as a server process its use is not without potential problems. For example, there will be no user present to respond to script error dialogues or other such prompts.
A publishing license (sxlic.exe) from MeadCo is required to enable server-side printing, and both the sxlic.exe and ScriptX.exe executables should be installed (executed) on your Windows NT4 or Windows 2000 server.
The following test files (as .zip archives) are available, these are described below:
It is strongly recommended that an evaluation license is obtained from MeadCo and a suitable server set aside for testing and evaluation - installation and configuration of the components may require several re-boots in order to achieve the settings required in a particular scenario. Following successful test deployment and evaluation, the set of steps and/or configurations necessary for deployment to production servers within your environment/scenario will have been determined.
ASP.NET If you intend to use ScriptX Printing with ASP.NET we recommend that you first configure and test the system using the old form Active Server Pages (.asp files). There are a number of additional considerations when working with ASP.NET that further complicate configuration - using .asp files reduces the number of potential causes of failure.
The following steps should be undertaken while logged onto the server machine under an account with Administrator privileges.
<%@ LANGUAGE="VBScript"%> <HTML> <HEAD><TITLE>ScriptX Printing Server Test 1</TITLE></HEAD> <BODY> <H1>Testing ScriptX Printing.</H1> <% dim factory,b Set factory = CreateObject("ScriptX.Factory") on error resume next b = factory.printing.IsSpooling if err.Number <> 0 then Response.Write "Printing is not licensed: " & err.description & " (Error code: " & err.Number & ")" else Response.Write "Printing is licensed." end if factory.ShutDown set factory = nothing %> </BODY> </HTML>
Navigate to the page using Internet Explorer and verify that the page is displayed without errors and printing is licensed. This test ensures that the ScriptX components are correctly installed.
Note: If the above test fails with a 0113 error (Script timed out), it is most likely that Application Protection is not set to Low (IIS Process) on the virtual directory.
<%@ LANGUAGE="VBScript"%> <HTML> <HEAD><TITLE>ScriptX Printing Server Test 2</TITLE></HEAD> <BODY> <H1>Testing ScriptX Printing.</H1> <% dim factory Set factory = CreateObject("ScriptX.Factory") Response.Write "The page headers are: " & factory.printing.header factory.printing.header = "ScriptX Printing - Printing at the Server" Response.Write "The updated page headers are: " & factory.printing.header factory.ShutDown set factory = nothing %> </BODY> </HTML>
Navigate to the page using Internet Explorer and verify that the page is displayed without errors. This test ensures that the ScriptX components are correctly installed and the default printer for the current interactive account is accessible.
Note: If the above test fails with "Unspecified error" the most likely cause is that a valid printer is not available and cannot be accessed.
<%@ LANGUAGE="VBScript"%> <HTML> <HEAD><TITLE>ScriptX Printing Server Test 3</TITLE></HEAD> <BODY> <H1>Testing ScriptX Printing.</H1> <% dim factory Set factory = CreateObject("ScriptX.Factory") factory.printing.header = "ScriptX Printing - Printing at the Server" factory.printing.footer = "Printed at the server" factory.printing.printHTML "http://localhost/default.asp" ' Change this URL to an appropriate page on your server. factory.ShutDown set factory = nothing %> <p>The page has been printed</p> </BODY> </HTML>
Navigate to the page using Internet Explorer and verify that the page is displayed without errors. This test ensures that the ScriptX components are correctly installed and the default printer for the current interactive account is accessible and printing to the printer.
Note: If the above test fails with "Unspecified error" the most likely cause is that a valid printer is not available and cannot be accessed.
The above steps complete the initial deployment of ScriptX Printing server side and validate that ScriptX can be successfully used on the server. However, as configured after initial installation, there are two undesirable aspects:
Before making the changes discussed here, the server should be rebooted (or the IIS Process stopped and restarted) to ensure that the ScriptX Components are unloaded from the IIS Process (IIS caches used component DLLs).
Application Protection
ScriptX Printing version 6.1.429.14 and later support setting ASP Application Protection to medium or high.
The ASP worker process will run under either the IUSR_<machinename> account (medium protection) or IWAM_<machinename> (high protection). These accounts must have "Log on as a batch job" rights and must also have permission to launch DCOM servers and access DCOM servers (in particular the "MeadCo TriPrint Server" object - DComCnfg can be used for this).
After changing the protection level and appropriate configuration with dcomcnfg.exe it is suggested that the above tests are run again to ensure successful operation.
Note: If the tests fail with the error "Unable to create ActiveX Object" the most likely cause is that the IUSR/IWAM accounts do not have "Log on as a batch job" rights or do not have permission to launch DCOM servers.
Running ScriptX Printing under a specific user account
Running ScriptX Printing under a specific user account removes the necessity for an interactive user to be logged onto the server machine. There is no necessity for the account to be used to have "Administrator" rights. However, it must:
- Have "Log on as a batch job" rights.
- Have a properly configured Internet Explorer (in other words, log on to the account and ensure that the web pages to be printed can be accessed).
- Have a functional default printer available - ScriptX Printing must be able to read the settings of the default printer.
- Have access rights to the printer to be used.
- Have DCOM access rights to the MeadCo Triprint Server object.
As discussed here: HOWTO: Configure Office Applications to Run Under a Specific User Account, if the account to be used is not already logged on, its registry hive will not be used, the "Default User" hive will be used instead. Although the default hive can be configured with access to the required printer(s), since ScriptX Printing requires read and write access to various parts of the hive (for example to store print header/footer settings) this is not recommended. It is recommended that a "null" service is used instead, as discussed in the above article. If the account to be used for ScriptX Printing is not already in use for a service, a suitable service is available here: Service.zip. After downloading, unpack the .zip file to a suitable location and follow the instructions given in the readme file.
To configure ScriptX Printing to use a particular account, use DComCnfg to configure the application "MeadCo TriPrint Server" with the required Identity.
After configuration, it is suggested that the above tests are run again to ensure successful operation.
Note: If the tests fail with the error "Unable to create ActiveX Object" the most likely cause is that the credentials (e.g. password) specified to a "This User" identity are wrong.
Printing
To print, the configuration parameters of the ScriptX Printing object may be used to set properties such as the printer to be used and headers and footers. To perform the print, the printHTML method is used, for example:
<% ' the object is dynamically created and destroyed set factory = CreateObject("ScriptX.Factory") factory.printing.PrintHTML "http://localhost/orders/order.asp?number=" & Request.Form("number") ' After use, shut down the object to ensure that resources ' are released in a timely manner factory.ShutDown set factory = nothing %>Please note: HTML files printed by PrintHTML calls on the server-side are download and printed in a separate process which is absolutely unrelated to the current user's ASP session context, including any authentication that has occurred by the remote user, either through an authentication dialogue or automatic authentication through, for example, NTLM. If the page to be printed is secured in some way, it must be accessible by the separate process Internet Explorer without any user intervention - this may require that automatic authentication is enabled. In the above example, http://localhost/ based URLs are printed so technically this is still the same HTTP server, but in fact any URL may be used. The only way to pass any contextual information is via the query part of the URL itself (the strings that follows the question mark).
To successfully use ScriptX Printing with ASP.NET, the MeadCo TriPrint Server object should be configured to run under a named account, as described for ASP deployment and the IIS application configured as medium or high protection.
In addition, the ASPNET account may need to be added to the list of accounts with launch and access rights on the MeadCo TriPrint Server object.
The use of the component is essentially as described in the Printing section above, however, a number of rules must also be followed when using the component within an aspx page:
The page must have the attribute aspcompat=true:
<%@ Page aspcompat=true Language="VB" debug="true" %>
Due to lazy release of COM objects by the .NET CLR garbage collection, timely release of the components must be forced or orphaned processes can result. It is also required that a specific reference to the printing object is made so that this can be released properly:
<script language = "vb" runat = "server"> Sub ScriptXPrint() dim factory as Object Dim printing as Object dim i as Integer Try ' Create the ScriptX object factory = CreateObject("ScriptX.Factory") ' Get the printing object - this allows for more efficient access ' and also enables timely release of the objects printing = factory.printing ' perform some printing printing.header = "ScriptX Printing - Printing at the Server" printing.footer = "Printed at the server" printing.printHTML("http://localhost/default.htm") ' Change this URL to an appropriate page on your server. Catch e as Exception Response.Write("Print failed: " + e.Message) End Try if NOT factory is nothing then ' Closedown the ScriptX object - *required* factory.ShutDown() ' Now ask .NET to release the objects. There should be only one reference ' on each object, but we loop until there are no references just in case. i = System.Runtime.InteropServices.Marshal.ReleaseComObject(printing) while i>0 i = System.Runtime.InteropServices.Marshal.ReleaseComObject(printing) end while i = System.Runtime.InteropServices.Marshal.ReleaseComObject(factory) while i>0 i = System.Runtime.InteropServices.Marshal.ReleaseComObject(factory) end while end if factory = nothing End Sub </script>