Server Side, Get from Raw HTML, HTML Formatted and then to Printer

Jan 22 2004 2:35 PM
Hello, This is my situation. I have to run a large number of reports that take a while to print and the printed version needs to be exactly like the client side displayed version. Because of the time length required to print all the reports, I want to shift the process to the server which will handle the printing instead of the client( No client side interation besides launching the printing thread. ) I have searched the web for an answer or help thus far I have not come up with much to get from formatted hmtl on the server to a printer. I don’t have the time to write my method to handle all the formatting of the html so I was hoping to find a more practical solution. I found a number of VB developers using a Browser approach: They would use the mshtml.DLL & SHDocVw.DLL (Windows/System32 directory) to create a browser and then run the ExecWB method to print. 1) Created the AxSHDocVw.DLL out of SHDocVw.DLL using AxImp.exe. 2) Added the references mshtml.DLL and AxSHDocVw.DLL. 3) Here is the snippet to create the browser( Orginal page I found this on: http://weblogs.asp.net/kaevans/archive/2003/02/25/2936.aspx ) InitializeComponent() string url = "about:blank"; object o = System.Reflection.Missing.Value; browser.Navigate ( url,ref o,ref o,ref o,ref o); AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler handler = new AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler (this.browser_StatusTextChange); browser.StatusTextChange += handler; private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.browser = new AxSHDocVw.AxWebBrowser(); ((System.ComponentModel.ISupportInitialize)(this.browser)).BeginInit(); this.SuspendLayout(); // // browser // this.browser.Enabled = true; this.browser.Location = new System.Drawing.Point(16, 16); this.browser.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("browser.OcxState"))); this.browser.Size = new System.Drawing.Size(344, 224); this.browser.TabIndex = 0; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(392, 302); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.browser }); this.Name = "Form1"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.browser)).EndInit(); this.ResumeLayout(false); } private void browser_StatusTextChange (object sender, AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent e) { mshtml.HTMLDocument doc = shtml.HTMLDocument)this.browser.Document; doc.body.innerHTML = "

foo

"; } This code rendered HTML find in the browser window. 4) This is what I tried to do to print the HTML Form1 x = new Form1(); x.Refresh(); object pvaIn = null; object pvaOut = null; x.browser.ExecWB( SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref pvaIn, ref pvaOut ); I got this error: An unhandled exception of type: ‘System.Runtime.InteropServices.COMExceptoin’ occurred in ashdocvw.dll Addition information: Trying to revoke a drop target that has not been registered. I searched the web for the error and found some VB developers talking about using a method QueryStatus I found the method on the browser class but was not sure what it is and how to use it. x.browser.QueryStatusWB( SHDocVw.OLECMDID.OLECMDID_PRINT); Anyway, I am stumped trying to get from HTML to the Printer on the Server side. I thought of using Crystal reports however no time to rewrite a report. I do not know all the method calls in those libraries C# or Crystal reports. Are there some that can read in HTML and print to the printer? Thanks for any help, Jeff