HTML渲染为图像 [英] Render HTML as an Image

查看:133
本文介绍了HTML渲染为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我产生的优惠券基于动态输入和裁剪图像,我使用NTML和CSS现在显示优惠券,问题是,印刷这已成为因打印时的背景是如何消失的问题和其他的问题,所以我认为最好的解决办法是能够基于HTML生成图像,或设立某种形式的模板,它接受字符串和图像,并生成使用反馈作为一个背景图像的图像并把顶部的优惠券信息。

I'm generating a coupon based on dynamic input and a cropped image, and I'm displaying the coupon using ntml and css right now, the problem is, printing this has become an issue because of how backgrounds disappear when printing and other problems, so I think the best solution would be to be able to generate an image based on the html, or set up some kind of template that takes in strings and an image, and generates an image using the image fed in as a background and puts the coupon information on top.

有什么,已经做了这个?

Is there anything that does this already?

这是一个ASP.NET 3.5的C#网站!

This is for an ASP.NET 3.5 C# website!

先谢谢了。

编辑:这将会是巨大的,如果输出有可能成为基于HTML的输入,如优惠券是通过操作使用jQuery的DOM和拖拽的东西设计的,这一切工作正常,它只是当它涉及到印刷(纸)有Z-索引问题。

edit: It'd be great if the output could be based on the HTML input, as the coupon is designed by manipulating the DOM using jQuery and dragging stuff around, it all works fine, it's just when it comes to the printing (to paper) it has z-indexing issues.

推荐答案

你可以做的是创造改变响应类型是你想要的格式,然后将图像插入流中aspx页面。我创建了一个酒吧code发电机,做类似的事情。不包括生成图像的所有手续,你的Page_Load会是这个样子:

What you can do is create an aspx page that changes the response type to be in the format you want and then put the image into the stream. I created a barcode generator that does a similar thing. Excluding all the formalities of generating the image, you'll Page_Load will look something like this:

Bitmap FinalBitmap = new Bitmap();
MemoryStream msStream = new MemoryStream();

strInputParameter == Request.Params("MagicParm").ToString()

// Magic code goes here to generate your bitmap image.
FinalBitmap.Save(msStream, ImageFormat.Png);

Response.Clear();
Response.ContentType = "image/png";

msStream.WriteTo(Response.OutputStream);

if ((FinalBitmap != null)) FinalBitmap.Dispose();

这就是它!然后你有你的形象做的是设置的URL是类似RenderImage.aspx?MagicParm =呜呼或任何你需要的。这样,你可以把它渲染任何你想做的指定。

and that's it! Then all you have to do in your image is set the URL to be something like RenderImage.aspx?MagicParm=WooHoo or whatever you need. That way you can have it render whatever you want to specify.

这篇关于HTML渲染为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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