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?
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.
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");
}
}
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.
Related
Good Morning,
I have a Web browser embedded within a C# winform. When loading the web-browser, it loads in a local file and displays the page with no issues.
I then have a button with an OnClick method which does the following:
private void button1_Click(object sender, EventArgs e) {
this.webBrowser1.Navigate("about:blank");
HtmlDocument doc = this.webBrowser1.Document;
doc.Write(String.Empty);
this.webBrowser1.DocumentText = //PathToDocumentText;
}
This was taken from this SO question and causes the web browser to freeze up. On hover shows the cursor with the loading spinning icon.
I am simply wanting to change the document text from one local file to another (both work if I load them in manually OnLoad).
Any help appreciated.
this.webBrowser1.Navigate("about:blank");
this.webBrowser1.Document.OpenNew(false);
this.webBrowser1.Document.Write(//pathtoFile);
this.webBrowser1.Refresh();
This does the trick, Thanks to anyone who looked at this.
I'm creating a image as a signature for Outlook, so im creating a template that my co-workers can edit to their own personal information.
But i want the company site, personal linkedin, and company facebook in the document as links. So when you click on it it sends you to the site (a link usually does that )
This is what the image looks like when i convert it to an image:
As you can see in the image you have a couple of thinks that should be filled in by the person using the application. The image is a panel that is converted with this code:
private void ConvertToImageButton_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(BackgroundPanel.Width, BackgroundPanel.Height);
BackgroundPanel.DrawToBitmap(bmp, BackgroundPanel.Bounds);
bmp.Save(#"C:\Users\collin-k\repo\test.png", ImageFormat.Png);
}
**Question: **
How can i add links to the image on a specific place, lets say the place of the website label.
Is this even possible or do you have another idea for a signature that looks like this. The image is a easy way because you can easily edit it.
Having a bit of trouble getting started on making a simple HTTP image browser. I am doing this in C# and using a Windows Form Application. The requirements included are that I prompt the user for a URL of an image which is inputted in a textbox (I believe I have to use an HTTPwebRequest, but not sure), and then click a button and display the image in a picturebox. I'm used to writing console applications, and am brand new to the Windows Forms commands, which is why I'm looking for some help.
**In addition, but not necessary, is the inclusion of a status code of the image, as well as associated headers that are returned by google's web server, which are displayed in textboxes. Sorry if this is too vague, I am just completely lost, and anything would help.
If you drop a TextBox, a Button and a PictureBox onto your form, you can use the code below to download an image from the internet, convert it to an image and show it in the PictureBox.
m_urlTextBox is the TextBox the user can use to enter the image URL.
m_downloadButton is the button that the user clicks to initiate the download.
m_pictureBox is the PictureBox used to draw the downloaded image.
The code for the Click event handler for the download button is shown below.
private void m_downloadButton_Click(object sender, EventArgs e)
{
using (var client = new WebClient())
{
var imageData = client.DownloadData(m_urlTextBox.Text);
var converter = new ImageConverter();
var image = (Image)converter.ConvertFrom(imageData);
m_pictureBox.Image = image;
}
}
I've made no attempt to handle errors or conversion failures, but this should give you the gist of what is required. If you need to inspect the headers associated with the image, you should look into WebRequest.Create / GetResponse / GetResponseStream etc. instead of using WebClient.
I'm currently trying to look at a directory, and then preview a .jpeg from a list box. I have the list box populating with the contents of the directory and only showing Jpegs, but I can't think of what to do to get the jpeg preview in a picture box. I'm using an asp .net application on Visual Studio 2010.
This is the code I have
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo infoDir = new DirectoryInfo(#"G:\Test_Directory");
FileInfo[] infoFile = infoDir.GetFiles("*.jpeg");
foreach( FileInfo file in infoFile )
{
lstDirectory.Items.Add(file.Name);
}
}
protected void lstDirectory_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
I'm under the understanding Postback needs to be used. If anyone is able to help, that would be great.
The file which is in the G: Drive, is a jpeg, which can be seen in the list box is : jpegimage.jpeg
Thanks.
How about something like this?
I think you could do this mostly in Javascript, with two additional ASP.NET page.
First, create a new web page. We'll call this A.aspx. This page will be passed the image name in the query string. It will be very simple: it will just fetch the contents of the file from "G:\TestDirectory" and write it to the Response stream. There are quite a few questions and answers on Stack Overflow on how to do this, if you haven't done it before.
Then, create another web page. We'll call this B.aspx. This will have an image control with height and width set appropriately. It will also take the image name from its query string. The code-behind will build a URL to use as the ImageSource property on the image control. The URL will be that of A.aspx, with the (URL-encoded) image name appended as a parameter.
On your ASP.NET page, hook up an event handler to your listbox. When the selected index on the list box changes, on the client side, build a URL, based on the URL to B.aspx with the image name from the list box appended as a parameter. Then open a window, using the URL you just built, pointing to B and passing the desired file name.
So: when the list box selected index changes (or when you double click, or whatever event you pick), the javascript will open a window with page B.aspx. Page B will have an image control, set to the URL to A.aspx. A.aspx will stream the image contents to the image control, which will appear in your new window.
I'm currently designing a web-based (asp.net/C#) volume tracking tool for a company which is used for reporting and rendering volume data. One way for the user to render data is through using a chart tool which uses the asp.net built-in chart. The user can set plenty of different filtering options to customize his chart appropriately and then have it rendered on the same page. Regarding the contents of the chart everything is working quite alright, however I have created a few controls for giving the user the possibility to generate higher quality images of their graph and show them in a separate window. Using an extension method for Response.Redirect I am redirecting the user to a new window that contains the high resolution version of the chart image, as can be seen below:
private void DownloadImage(int width, int height)
{
double scale = width / ViewGraphChart.Width.Value;
// Resize chart:
ViewGraphChart.Width = width;
ViewGraphChart.Height = height;
// Resize titles:
foreach (Title t in ViewGraphChart.Titles)
{
t.Font = new Font(t.Font.FontFamily, (float)(t.Font.Size * scale), FontStyle.Regular);
}
// Resize legends:
foreach (Legend l in ViewGraphChart.Legends)
{
l.Font = new Font(l.Font.FontFamily, (float)(l.Font.Size * scale), FontStyle.Regular);
}
UpdateChart();
// Open image in new window:
Response.Redirect(ViewGraphChart.CurrentImageLocation, "_blank", "");
}
So far so good, a new window opens up and the user is handed a high resolution version of his chart image. The problem is however that the chart in the tool also, naturally, is modified and obviously becomes way too big to properly fit inside the layout. I tried to remedy this by resetting the chart properties right after the redirect, this however made the "HD" chart image show up as the same tiny chart image inside the tool. So, I figured the best way would be to make a copy of the chart, modify the copy and hand it to the user, while the original image remains its small size within the tool. Is there any simple way to do this, considering that I have tons of databindings and other things connected to my chart, or is there some other way to go about?
I'm in somewhat of a hurry so if this came out rather unclear, please tell me and I'll explain more thoroughly.
Regards,
Ante
Edit:
The code behind the Response.Redirect extension method. Borrowed from this very page if I remember correctly.
public static void Redirect(this HttpResponse response, string url, string target, string windowFeatures)
{
if
((String.IsNullOrEmpty(target) || target.Equals("_self", StringComparison.OrdinalIgnoreCase))
&& String.IsNullOrEmpty(windowFeatures))
{
response.Redirect(url);
}
else
{
Page page = (Page)HttpContext.Current.Handler;
url = page.ResolveClientUrl(url); string script;
if (!String.IsNullOrEmpty(windowFeatures))
{
script = #"window.open(""{0}"", ""{1}"", ""{2}"");";
}
else
{
script = #"window.open(""{0}"", ""{1}"");";
}
script = String.Format(script, url, target, windowFeatures);
ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", script, true);
}
}