/// <summary> /// 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. /// </summary> /// <param name="operation">Print or Preview?</param> 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); } } }
/// <summary> /// PrintOrPreview the document displayed in the WebBrowser. /// Adds the ScriptX factory to the page if required, or uses it if already there /// Defines custom headers and footers for the print and as we are licensed /// we can set margin measure (and could set a whole lot of other things!) /// /// Note that we dont add security manager to the html document, the app is licensed /// so it isnt needed. /// </summary> /// <param name="operation">Print or Preview?</param> 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"; // use some advanced features ... printer.SetMarginMeasure(2); // set units to inches printer.leftMargin = 1.5f; printer.topMargin = 1; printer.rightMargin = 1; printer.bottomMargin = 1; // and html headers/footer .... v7.7 and earlier only support allPagesHeader/Footer and firstPageHeader/Footer from // applications. var ef = factory.printing.enhancedFormatting; ef.allPagesHeader = "<div style='border: 1pt solid red; font: bold 12pt Arial; background: threedface; color: navy; padding-top: 5px; padding-bottom: 6px; background-image: url(http://www.meadroid.com/images/non_act_bg.jpg)'><i><center> --- Header for page <b> &p </b> ---</i></center></div>"; ef.allPagesFooter = "<div style='border: 1pt solid red; font: bold 12pt Arial; background: threedface; color: navy; padding-top: 5px; padding-bottom: 6px; background-image: url(http://www.meadroid.com/images/non_act_bg.jpg)'><i><center> --- Footer for page <b> &p </b> ---</i></center></div>"; switch (operation) { case PrintOperation.Print: printer.Print(false); // prompt will only be obeyed on intranet break; case PrintOperation.Preview: printer.Preview(); break; } // and we can wait untiol the job is spooled and so let the user know its on its way printer.WaitForSpoolingComplete(); MessageBox.Show("The print has completed.", this.Title); } else { MessageBox.Show("Unable to find or create MeadCo ScriptX.\n\nIs MeadCo ScriptX installed?", this.Title); } } }