How to convert block of html to an image (e.g. jpg) in asp.net

痞子三分冷 提交于 2019-12-08 11:20:58

问题


I would like to convert html (for example, a table) to an image and save it as a .jpg file. And, if that table is displayed within a web page along with other elements, I only want to get that specific table and save it as an image.

Is this possible using asp.net?

thanks


回答1:


I think this is a rendering issue and completely depends upon what browser rendering your HTML.

But this the closest thing I could get you using GDI+ and WebBrowser control from CodeProject.

Let me know whether it helped you or not!

Regards.




回答2:


We have used http://iecapt.sourceforge.net/ to convert HTML to image. You can try it out. It is available for FREE.

or

ref

http://stackoverflow.com/questions/1972739/convert-a-html-control-div-or-table-to-an-image-using-c



回答3:


<%@ Page Language="c#"%> 
<%@ Import Namespace="System.Drawing.Imaging" %> 
<%@ Import Namespace="System.Drawing" %> 
<%@ Import Namespace="System.Drawing.Drawing2D" %> 

<script runat="server"> 
private void Page_Load(object sender, System.EventArgs e) {   
Bitmap bmp= new Bitmap(Server.MapPath(Request.QueryString["i"]));   
Graphics g=Graphics.FromImage(bmp);   
g.SmoothingMode = SmoothingMode.AntiAlias ;   
g.DrawString(Request.QueryString["t"],    
new Font("verdana",12),SystemBrushes.WindowText, 1, 1);   
Response.ContentType="image/jpeg";   
bmp.Save(Response.OutputStream, bmp.RawFormat) ; } 
</script>


来源:https://stackoverflow.com/questions/3165318/how-to-convert-block-of-html-to-an-image-e-g-jpg-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!