Convert a HTML Control (Div or Table) to an image using C#

后端 未结 6 1075
滥情空心
滥情空心 2020-12-14 03:52

Is it possible to convert a Html Control to an image in C#?

Is there any C# method where I can pass the Html Control object and return an image of that html control?

6条回答
  •  失恋的感觉
    2020-12-14 04:14

    The control you're describing has, as its output, HTML. That's all it does.

    Your problem is that you want to turn a snippet of HTML into an image. Rendering HTML is done by a browser - ASP.NET has basically nothing to do with how HTML is rendered by a client.

    Most .NET libraries that do this job (turning HTML into images) use IE to power the conversion. Some of those utilities include:

    1. Websites Screenshot - http://www.websitesscreenshot.com/
    2. The aforementioned htmlsnapshot - http://www.guangmingsoft.net/htmlsnapshot/help.htm
    3. Basically any HTML -> PDF library has this functionality, including ABCPdf - http://www.websupergoo.com/abcpdf-1.htm

    But the more basic answer to the question is that ASP.NET controls don't render to an image format. You'll have to do an IE screenshot of a page that has only that control (or HTML) on it.

提交回复
热议问题