如何在Asp.net中打印Html输出 [英] How to Print Html output in Asp.net

查看:165
本文介绍了如何在Asp.net中打印Html输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须打印到html输出。我试过,但我不能打印html输出,但其打印HTML代码



i have to print to html output . i have tried but i cant able to print html output but its printing html code

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();
   }     
}



但我无法打印html输出。只有HTML代码





我知道但是我将如何在网上使用它。通过添加System.Window.Form.WebBrowser的任何refence。我没有得到什么是dll名称



你可以帮帮我


but i can't able to print html output. only html code


ya i know but how i will use this in web . By adding any refence of System.Window.Form.WebBrowser. i am not getting what is the dll name

Can u pls help me

推荐答案

我不喜欢知道你真正想做什么吗?



如果你想在浏览器中将html代码显示为文本,你需要使用其中一个来编码它code> HtmlEncode(...)方法。



尼克
I don't know what you are actually trying to do?

If you want to display the html code as text in a browser, you need to encode it using one of the HtmlEncode( ... ) methods.

Nick


如果我正确理解您,您想在连接到服务器的打印机上打印html页面吗?这听起来很奇怪,特别是对于一个网络应用程序。



无论如何,如果是这种情况,你需要一个html渲染引擎。最容易使用的是 System.Windows.Forms.WebBrowser 控件。



创建一个实例并将 DocumentText 属性设置为您的html字符串。处理加载html时触发的 DocumentCompleted 事件。然后设置你的打印作业并调用 WebBrowser.Print()



我无法想象为什么你我想这样做,但是:confused:



Nick
If I understand you correctly, you want to print an html page on a printer attached to your server? This sounds odd, especially for a web app.

Anyway, if that is the case, you need an html rendering engine. The easiest one to use is the System.Windows.Forms.WebBrowser control.

Create an instance of one and set the DocumentText property to your html string. Handle the DocumentCompleted event which fires when the html is loaded. Then set up your print job and call WebBrowser.Print().

I can't imagine why you would want to do this, though :confused:

Nick


我想打印html输出意味着显示的内容浏览器。

步骤我已经完成了

1)阅读A.html文件

2)将其写入浏览器

3)通过服务器端打印html输出。不是客户端代码要打印html输出我已经使用了服务器端System.Drawing.PtintDocument类,但是我无法打印html输出但是它的打印html代码就像......
Exactly i want to print the html output means whatever displayed on browser .
Step i have done
1) read the A.html file
2) write it to the browser
3) print the html output through server side. not client side code To print the html output i have used server side System.Drawing.PtintDocument Class but i cant able to print html output but its printing html Code like ......


这篇关于如何在Asp.net中打印Html输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆