.Net RTF(或)HTML 到图像
在.Net(C#)服务器进程中,我想生成带有大量富文本(带有段落、字体样式等)的图像。富文本可以使用 RTF 或 HTML 来描述。
有什么方法可以将 RTF/HTML 转换为图像吗?由于它是一个服务器进程,我想避免 Windows 窗体控件。
In .Net (C#) server process, i want to generate image with lot of rich text (with paragraphs, font style, etc.. ). The richtext can be described using RTF or HTML.
Is there any way to convert RTF/HTML to a image ? Since it is a server process, i want to avoid windows forms controls.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用虚拟打印机并打印到图像。
You could possibly use a virtual printer and print to an image.
不确定你想做什么。
如果它就像在服务器上自动生成用户的通过证书,然后他们可以打印出来,那么我将使用通用处理程序 .ashx 并在内存中构建图像,然后将其写入响应。
如果最终用户将文本等放入浏览器并发回,请查看网络浏览器控件,或者如果您愿意,它是 activex 的前身(IMO 功能更丰富)。我知道您想避开表单方面的事情,但您可以在内存中创建和使用这些控件之一。我认为可以在浏览器中渲染返回的 html(您可能必须使用一些 javascript 和隐藏字段来获取纯 HTML,而不会出现视图状态问题)。从那里可能可以抓取或打印屏幕(或者如果控件实际显示的话屏幕上会出现什么)!我确信我以前在某个地方使用过这种闪避。
请给我更多详细信息,我会尽力为您提供一些示例。
not sure what you are trying to do.
If it is like autogenrating on the server a pass certificate for a user which they can then print off then I would use a generic handler .ashx and build the image in memory then write it to the response.
If the end user is putting the text etc into their browser and posting back then have a look at the webbrowser control or if you prefer, it's activex predecesor (which is more feature rich IMO). I know you want to steer away from the Forms side of things but you can create and use one of these controls in memory. I'm thinking it would be possible to render the returned html in the browser (you might have to use some javascript and a hidden field to get the plain HTML without the viewstate issues). From there it might be possible to grab or print the screen(or what would have been on the screen if the control had actually been displayed)! I'm sure I've used this dodge before, somewhere.
Give me some more details and I'll try and get some examples together for you.
如何保存richTextBox 作为 jpg 文件?
how to save the content of richTextBox as jpg file?
您可以查看 Snowbound Rastermaster(商业 SDK)。也许他们能够胜任你的任务。
http://snowbound.com/rastermaster_net/net_overview.html
You can look into Snowbound Rastermaster (commercial SDK). Maybe they will be mission capable for you.
http://snowbound.com/rastermaster_net/net_overview.html
phantomjs(无头 WebKit 浏览器)可用于将渲染的 HTML 页面转换为图像。
从 http://phantomjs.org/download.html 安装它并从命令行执行以下示例脚本:
它将在 JPEG 文件中创建给定页面的屏幕截图。
phantomjs (a headless WebKit browser) could be used to convert rendered HTML page into image.
Install it from http://phantomjs.org/download.html and execute the following sample script from command line:
It will create a screenshot of given page in JPEG file.