4

I am developing a web application that has an interactive feedback tool for users. In this application users can click a send feedback button. The button puts up an overlay over their current web page and allows them to drag highlight area DIVs to emphasize certain areas. Once they submit their feedback the HTML of the entire page is passed via AJAX back to the server.

Once on the server I now have a string containing the HTML of the page. From here I would like to run this string through some sort of engine that renders the HTML and builds an image. A sort of round about way of taking a screenshot if you will.

How might one accomplish something like this? Are there engines available that are written in C# and can build up the HTML and render an image?

Mrchief
  • 75,126
  • 20
  • 142
  • 189
CatDadCode
  • 58,507
  • 61
  • 212
  • 318

3 Answers3

2

You can consider usin LLMozLib if you want to go by Gecko.
See more details here

EDIT

There's an ActiveX control to embed Gecko on Windows.
Sample here

EDIT

I got it working on a Windows Forms application.
Using these resources.
It is a csharp wrapper to Gecko ...

That's my sample code ...

public partial class Form1 : Form
{
    public Form1()
    {
        Xpcom.Initialize(@"C:\Users\esouza\Downloads\xulrunner"); //Tell where are XUL bin
        InitializeComponent();
        //geckoWebBrowser1 is an instance of GeckoWebBrowser control that I've dragged on the Form1
        geckoWebBrowser1.DocumentCompleted += new EventHandler(geckoWebBrowser1_DocumentCompleted);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        geckoWebBrowser1.Navigate("http://www.google.com");
    }

    void geckoWebBrowser1_DocumentCompleted(object sender, EventArgs e)
    {
        Bitmap b = new Bitmap(geckoWebBrowser1.Width, geckoWebBrowser1.Height);
        geckoWebBrowser1.DrawToBitmap(b, new Rectangle { X = 0, Y = 0, Width = 800, Height = 600 });
        b.Save("file.bmp");
    }
}
Tocco
  • 1,655
  • 11
  • 14
2

Check out this framework - http://awesomium.com/

This is exactly what you need.

Set the base URL, this will be needed to resolve any relative URLs

WebCore.SetBaseDirectory("C:\\MyApplication\\MyBaseDirectory");

Then load the HTML -

myWebView.LoadHTML("<p>Hello World!</p>");

Then use the .Render() method, and you'll be able to save the rendered content to an image.

Maxim
  • 7,268
  • 1
  • 32
  • 44
  • D: except not for $2900!!! Dang... Sadly our company makes a lot more than $100k but I know they will not spring for $2900 because what I want it for is relatively simplistic. – CatDadCode Jul 20 '11 at 14:56
  • It looks like if I want to go the cheap route I'm going to have to stick to the way Google+ does it and use the `canvas` tag in HTML 5 to draw a screenshot. Then just limit the functionality in HTML 4 browsers. – CatDadCode Jul 20 '11 at 14:59
0

Very interesting question and I've not got a silver bullet for you.

You're surely going to need a browser engine of some description and then capture the rendered output as a bitmap.

I see from this question that there was a COM wrapper developed for WebKit. Maybe that's a good starting point.

Community
  • 1
  • 1
Steve Morgan
  • 12,978
  • 2
  • 40
  • 49