使用c#打印HTML文本 [英] Print HTML text using c#

查看:101
本文介绍了使用c#打印HTML文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I need to print html text using c#.

Now html looking

string strHTML="<html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";

推荐答案



试试这个..





Hi
Try this..


protected void Button1_Click(object sender, EventArgs e)
       {

           string strHTML = "<html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";
           LiteralControl literal = new LiteralControl();
           literal.Text = strHTML;
           this.Controls.Add(literal);
       }





更多信息:个人控件 [ ^ ]






你可以使用Webbrowser打印HTML。

请参阅以下链接。



http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.print.aspx [ ^ ]


我假设您希望HTML以文本形式显示在您的网站上,而不是以HTML格式显示?

如果是这样,那么只需使用HtmlEncode:

I assume that you want the HTML to appear on your site as text, rather than be actioned as HTML?
If so, then just use HtmlEncode:
string strHTML = Server.HtmlEncode("<html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>");


这篇关于使用c#打印HTML文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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