protected void Button1_Click(object sender, EventArgs e) { try { try { // print the document using PrintDocument PrintDocument doctoprint = new PrintDocument(); doctoprint.PrintPage += new PrintPageEventHandler(document_PrintPage); doctoprint.Print(); } finally { stream.Close(); } } catch (Exception ex) { Response.Write(ex.Message); } } //Event handle to print html private void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { float yPos = 0; float leftMargin = e.MarginBounds.Left; float topMargin = e.MarginBounds.Top; string line = null; Font printFont = new Font("Arial", 10); Byte[] buffer = null; //buffer = StreamFile(@"C:\\Documents and Settings\\sweta.rani\\Desktop\\2008-03-12_osam_pr.pdf"); buffer = StreamFile(@"C:\\Documents and Settings\\sweta.rani\\Desktop\\A.html"); if (buffer != null) { Response.ContentType = "text/html"; Response.AddHeader("content-length", buffer.Length.ToString()); Response.BinaryWrite(buffer); line = Encoding.ASCII.GetString(buffer); e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); Response.End(); } }
HtmlEncode( ... )
System.Windows.Forms.WebBrowser
DocumentText
DocumentCompleted
WebBrowser.Print()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)