Basic use

In basic (free) usage, ScriptX can be used with a web browser control (XAML WebBrowser control) displayed within the application to print the html displayed in the control.

The ScriptX factory object may be placed on the HTML document displayed in the control and utilised by script on the document or code from the host application. Or, the ScriptX object can be injected into the loaded HTML document and then its properties and methods called from the host application.

In both these cases, it is the HTML document displayed in the web browser control that is printed.

The following XAML code-behind shows the principle; assume that the following routine is called when a 'Print' button is clicked and that a WebBrowser control with the name 'webBrowser' is present on the XAML frame and has a document completely loaded:

///
/// PrintOrPreview the document displayed in the WebBrowser.
/// Adds ScriptX to the page if required, or uses it if already there
/// Defines custom headers and footers for the print.
///
///Print or Preview?
private void PrintOrPreview(PrintOperation operation)
{
var document = (IHTMLDocument3) WebBrowser.Document;

// 'de-facto' id is 'factory'
var factoryElement = document.getElementById("factory");

// does the factory object exist?
if (factoryElement == null)
{
   // If not then create it.
   ((IHTMLDocument2)WebBrowser.Document).body.insertAdjacentHTML("beforeEnd",
       factoryObjectHtml);

   factoryElement = document.getElementById("factory");
}

if (factoryElement != null)
{
   var factoryObject = (IHTMLObjectElement) factoryElement;

   // an element 'factory' exists, but is the object loaded (it may not be installed)?
   ScriptX.Factory factory = (ScriptX.Factory) factoryObject.@object;
   if (factory != null)
   {
      ScriptX.printing printer = factory.printing;
      printer.header = this.Title;
      printer.footer = "&D&b&b&P of &p";
      switch (operation)
      {
         case PrintOperation.Print:
            printer.Print(false); // prompt will only be obeyed on intranet
            break;

         case PrintOperation.Preview:
            printer.Preview();
            break;
      }
   }
   else
   {
      MessageBox.Show("Unable to find or create MeadCo ScriptX."
           "\n\nIs MeadCo ScriptX installed?",this.Title);
   }
}
}

See our Github repo for a complete sample (the project WpfApplicationFreeUse).

 

::> Advanced use licensing