How to display a string containing HTML in an image in C #?

I am developing a web application with an interactive feedback tool for users. In this application, users can click the send feedback button. The button overlays over the current web page and allows them to drag the DIV selection area to emphasize specific areas. When they submit their reviews, the HTML of the entire page is transmitted via AJAX back to the server.

Once on the server I now have a line containing an HTML page. From here I would like to run this line through some kind of engine that displays HTML and creates an image. An example way to take a screenshot if you want.

How can you achieve something like this? Are there any engines that are written in C # that can generate HTML code and display an image?

+4
source share
3 answers

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

This is exactly what you need.

Set the base URL, this will be necessary 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 can save the displayed content to the image.

+2
source

You can consider usin LLMozLib if you want to go on Gecko.
More here

EDIT

There is an ActiveX control for embedding Gecko in Windows.
Example here

EDIT

I worked on Windows Forms. Using these resources .
This is the csharp shell for Gecko ...

What is 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"); } } 
+2
source

A very interesting question, and I do not have a silver bullet for you.

You probably need a browser mechanism for some description, and then capture the displayed output as a bitmap.

I see from this question that there is a COM wrapper for WebKit. Perhaps this is a good starting point.

0
source

All Articles