如何使用MVC拍摄网站的屏幕截图? [英] How can I take a screenshot of a website with MVC?

查看:176
本文介绍了如何使用MVC拍摄网站的屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力寻找一种方法来对MVC4中的网站进行屏幕截图.我已经看到了两种潜在的解决方案,它们都不适合MVC.

I am struggling to find a way to take a screenshot of a website in MVC4. I have seen two potential solutions, which neither work well for MVC.

第一种方法是使用WebBrowser,教程发现此处,但这给了我ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment错误.

The first is using the WebBrowser, tutorial found here, but this gives me a ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment error.

另一个正在使用名为 Grabz.It 的第三方.将其集成到MVC中的方法.

The other is using a 3rd party called Grabz.It, but I haven't found a way to integrate it into MVC.

还有其他想法/解决方案吗?

Any other ideas/solutions?

谢谢.

推荐答案

鉴于您的其他详细信息,您应该可以使用任意数量的工具执行此操作. CodeCaster的想法很好,而且PhantomJS还提供了类似的基于Webkit的任意url生成图像( https ://github.com/ariya/phantomjs/wiki/Screen-Capture ).它提供了几种输出格式选项,例如PNG,JPG,GIF和PDF.

Given your additional details, you should be able to do this with any number of tools. CodeCaster's idea is fine, and PhantomJS also offers similar webkit-based image generation of an arbitrary url (https://github.com/ariya/phantomjs/wiki/Screen-Capture). It offers several output format options, such as PNG, JPG, GIF, and PDF.

由于PhantomJS使用的是WebKit,它是一个真正的布局和渲染引擎,因此它可以捕获网页作为屏幕截图.由于PhantomJS可以在网页上呈现任何内容,因此它不仅可以用于转换HTML和CSS中的内容,还可以用于转换SVG和Canvas中的内容.

Since PhantomJS is using WebKit, a real layout and rendering engine, it can capture a web page as a screenshot. Because PhantomJS can render anything on the web page, it can be used to convert contents not only in HTML and CSS, but also SVG and Canvas.

您可能需要从MVC应用程序执行phantomjs.exe应用程序,或者可能需要通过某些在后台运行的服务来处理提交的url队列,这可能会更好.

You would need to execute the phantomjs.exe app from your MVC app, or probably even better by some service that is running behind the scenes to process a queue of submitted urls.

这篇关于如何使用MVC拍摄网站的屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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