Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture a full website screenshot with C# and WebKit.NET?

I am using WebKit.NET to integrate a browser component in my C# application. The problem is I can only capture the visible part in the browser window with a screenshot. Is there a way to capture the screenshot of the whole page?

like image 979
topless Avatar asked Oct 24 '12 11:10

topless


2 Answers

Seems that it is kind of possible by using NativeMethods.SendMessage, although this can screw up the message queue, could you use http://cutycapt.sourceforge.net/ or perhaps http://iecapt.sourceforge.net/ or http://labs.awesomium.com/capturing-web-pages-with-c-net/?

like image 135
Paul Zahra Avatar answered Nov 09 '22 08:11

Paul Zahra


I use WebBrowser instead; ScrollBarsEnabled = false let me capture whole page.

Here is some code:

protected override void Render(HtmlTextWriter writer)
 {

        StringBuilder builder = new StringBuilder();
        HtmlTextWriter htw = new HtmlTextWriter(new StringWriter(builder));
        base.Render(htw);
        string html = builder.ToString();

        _Generate(html);
 } 


private void _Generate(string html)
{
    var browser = new WebBrowser { ScrollBarsEnabled = false };
    DisplayHtml(html, browser);
    browser.DocumentCompleted += WebBrowser_DocumentCompleted;
    while (browser.ReadyState != WebBrowserReadyState.Complete)
       Application.DoEvents();  
    browser.Dispose();
}

private void DisplayHtml(string html, WebBrowser browser)
{
    browser.Navigate("about:blank");
    if (browser.Document != null)
    {
        browser.Document.Write(string.Empty);
    }
    browser.DocumentText = html;
}
like image 26
Emanuele Greco Avatar answered Nov 09 '22 10:11

Emanuele Greco