简体   繁体   English

将简单的html转换为位图/图像的简单方法是什么?

[英]what is the easy way to convert simple html to bitmap/image?

In my project, i has many simple html text in database eg. 在我的项目中,我在数据库中有许多简单的html文本,例如。

<ul>this is apple</ul>
<ul>this is orange</ul>
<p>I want to <u>eat</u> apple</p>
hello <i>mr</i> orange

In my project, I have a server and a client. 在我的项目中,我有一个服务器和一个客户端。 the server will read the html text from database, the client is a web client, it must get the html text in form of Image object to display it.(I have my own reason not to display html text directly in DOM......), anyway the client must display everything in the form of image. 服务器将从数据库读取html文本,客户端是Web客户端,它必须以Image对象的形式获取html文本才能显示它。(我有自己的理由不直接在DOM中显示html文本.... ..),无论如何,客户必须以图像形式显示所有内容。

Now I think 2 approach to solve this problem. 现在我认为2种解决这个问题的方法。
the first one , server convert 'html text' into image (eg. base64 string) , then send it to client. 第一个是服务器将'html text'转换为图像(例如base64字符串),然后将其发送给客户端。
or ..... 要么 .....
the second one, client get the 'html text' and convert it by javascript to javascript image object in the browser. 第二个,客户端获取“ html文本”并将其通过javascript转换为浏览器中的javascript图像对象。

my server program is a dot net program. 我的服务器程序是一个点网程序。
my client is browser which can run html5, eg. 我的客户端是可以运行html5的浏览器,例如。 chrome, firefox. 铬,Firefox。

How can I do it? 我该怎么做?

I have done this before using the js plugin html2canvas 我已经在使用js插件html2canvas之前完成了此操作
It's not perfect, but it works pretty good, and maybe it improved since I last used it. 它并不完美,但是效果很好,也许自从我上次使用它以来,它已经得到了改进。

If you want to do it on the server side, you can crawl the page with a headless browser like phantomJs and have it create a screenshot for you, but this will probably be more complicated to setup. 如果要在服务器端执行此操作,则可以使用无头浏览器(如phantomJs)抓取页面并为您创建屏幕截图,但是设置起来可能会更加复杂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM