A simple example

Code on the server may handle an HTTP GET or POST request and print a report (a different HTML page) as part of some server-side application logic. 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.

To print, properties of the ScriptX Printing object may be set such as the printer to be used and headers and footers. To perform the print, the PrintHTML method is called, for example:

ASP.Net WebForms App (C#)

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
  MeadCo.Printing p;
  MeadCo.ScriptX.printing printer;
        
  string sReportUrl = Utils.AbsoluteUrl("~/content/docs/testreport.htm");
         
  try
  {
    p = new MeadCo.Printing();
    printer = p.Printer;
    if (printer != null)
    {
       try
       {      
         // Apply the required settings, this can include the printer, 
         // papersize, copies, orientation, bin etc.
         printer.header = "ScriptX Printing - Printing at the Server";
         printer.footer = "Printed at the server";

         // Note that the fully qualified URL must be provided,
         // it cannot be relative to the server since ScriptX does not
         // have access to context.

         // Do NOT specify prompt - there is no interactive user!
         // PrintHTML will add the url to the queue and start processing them
         // this page can continue to completion and return to the user.
         printer.PrintHTML(sReportUrl, 0);                                
       }
       catch (Exception ex)
       {
          Master.Log("ScriptX configuration problem: " + ex.Message);                   
       }
     }
     else
        Master.Log("Error creating printer objects: " + p.errorReason);

     p.Close();
   }
   catch (Exception ex)
   {
      Master.Log("Uncaught exception: " + ex.Message);
   }           
}    
</script>

In the above code utility classes are used to simplify coding. MeadCo.Printing is a class that wraps the MeadCo ScriptX COM components and performs actions such as enabling the licensing of the components. These utility classes are available in the Validation kit.

Classic ASP

<%
 ' Apply licensing - the license must already be installed.
 set secmgr = CreateObject("MeadCo.SecMgr")
 secmgr.Apply "","{XXXX-XXXX-XXXX-XX}",X

 ' the object is dynamically created and destroyed
 set factory = CreateObject("ScriptX.Factory")
 factory.printing.header = "Report printed on the server"
 factory.printing.footer = "Printed on &D"
 factory.printing.PrintHTML "http://localhost/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
%>

 

::> Installing ScriptX Server side / Remote Printing