How to Convert a Div content to image? - c#

I have a div and inside it exists one gridview and few other divs. Now I want to convert its contents to an image and store it on the server. I don't want to send it to client.
How can I do it?

The Page Content will be process in browser and browser is in client side
so you dont now how it seems in server side ,in server side we just have html and scripts ...
so the link ddrace gave may be usefull, or you can develope a windows App and put a webbrowser on it and load your page in the browser and save the image of browser to the server

You're going to have to use a piece of middleware to do this. I have used this one in the past: http://www.winnovative-software.com/Html-To-Pdf-Converter.aspx . I know it says "to PDF", but one of it's features is that it can render the result to an image and save it in various image formats.
In your web application, have the middleware components bring the web-page down that has your control etc on it, and save it as an image on the server.

Related

what is the easy way to convert simple html to bitmap/image?

In my project, i has many simple html text in database eg.
<ul>this is apple</ul>
<ul>this is orange</ul>
<p>I want to <u>eat</u> apple</p>
hello <i>mr</i> orange
In my project, I have a server and a client. the server will read the html text from database, the client is a web client, it must get the html text in form of Image object to display it.(I have my own reason not to display html text directly in DOM......), anyway the client must display everything in the form of image.
Now I think 2 approach to solve this problem.
the first one , server convert 'html text' into image (eg. base64 string) , then send it to client.
or .....
the second one, client get the 'html text' and convert it by javascript to javascript image object in the browser.
my server program is a dot net program.
my client is browser which can run html5, eg. chrome, firefox.
How can I do it?
I have done this before using the js plugin html2canvas
It's not perfect, but it works pretty good, and maybe it improved since I last used it.
If you want to do it on the server side, you can crawl the page with a headless browser like phantomJs and have it create a screenshot for you, but this will probably be more complicated to setup.

Getting the browser to show IFrame or use HttpOnly cookie on different page

Hello I'm developing a Windows Phone app for a web based game.
I have however run into a problem that I cant figure out how to solve, and hope some of you bright people in here have an idea.
I use a java script to log into the page no problem, but unfortunately the webpage is very badly designed and show up wrong on Windows Phone. The page will not scale and therefor only show a small part of the hole page and it is only possible to scroll up and down and not side ways.
I have made a quick image here to show better.
Link to image on ImageShack
(I dont have rep to post Images yet :-( )
So the actual game is inside an IFrame in the middle of the page but I can only see a small part of it on the phone and can not scroll horizontally.
I tried to download the page using string html = webBrowser1.SaveToString(); and then used a regex function to extract the webpage from the IFrame. The problem with this is that the page uses a HttpOnly Cookie and this cookie is used by the IFrame also to identify the user. So if I navigate directly to the IFrame Url, it wont recognize the user even though it has the cookie because it is on a different website..
So my question is is there a way to force the web-browser to focus on the IFrame, or some way of stripping out the rest of the page and only show IFrame but still use the same HttpOnly Cookie?
Can you make a wraps that iframe, then use the hastag trick ("http://game.com#divwrapper") to navigate to that div. This will scroll the page down

How to get the captcha when doing a webrequest?

I'm letting my users register an email account, the users just fills in all information in my program and my program will fill the fields. Well not really it makes a POST request with the correct postdata to the correct form/post url.
However the website requires a captcha, I just simply want to show the captcha to my user, he enters the value and then it gets send along with the postdata.
The register page is here: http://register.rediff.com/register/register.php?FormName=user_details
I can just get all image urls from the html but when I copy the url of the captcha image and go to it, it's a different image then the image i copied the url from:
http://register.rediff.com/register/tb135/tb_getimage.php?uid=1312830635&start=JTNG
How do I do this using HttpWebRequest ?
I can just grab the html first:
string html = new WebClient().DownloadString("http://register.rediff.com/register/register.php?FormName=user_details ");
Then get the image url but I don't know how to show the same captcha to the user?
Btw it's not for a bot... it's not something automated.. it's just I don't want the user to show the webinterface...
Not really answer, some advice instead:
If you're writing an app client to work with the website, a better approach would be to write a WCF/WebService for the App to interact with directly - this can just refer directly to your BL layer.
If you want the whole app to work on screen scraping then that's a lot of work ahead, and your app will be dependent on the site not being changed.

Forcing image to download

I'm using a WebBrowser control in Silverlight and I'm setting it to a local HTML page. The HTML page has various links and they all work fine. Can I make it so that if the user clicks on an image file, it downloads to their system (or does the default behavior of the broweser) instead of displaying on the webpage? The main question is, is it possible to do this if I don't have access to the server itself? Thanks
edit - Is it possible to send an HTTPWebRequest to get the image and then edit the response headers, all from the client? This may be an alternative.
The standard way of doing this is to send the Content-Disposition HTTP header with attachment as the value. See here for more on this: Uses of content-disposition in an HTTP response header
But if you don't have access to the server, I don't think you can achieve this.

how can i get the result of JavaScript function of another websites page in C#?

I've application that uses another web sites data so how can i get it because it uses some JavaScript functions to get that data and it not show in page view-source.
Check the NET tab in firebug, XHR and check the resource that is requested, and request the same resource.
Basically you have to render the webpage and ensure the javascript functions are run (evaluated). You could do this by "borrowing" their javascript files (by linking to them from your own page), but this may not work as you don't know what's in those files - they could be accessing DOM elements that you don't have in your page, or calling to other domains which may prevent them from working correctly.
The easiest way to show the same data is to just host the page inside an iframe on your own page. If you are looking to do this from a normal client application (i.e. not a web app) then you will need a browser control that you navigate to the target page. If the browser control is invisible you could then scrape values from it and show them in your app, although this is a very clumsy way to do it, and it's debatable about how ethical it is.
If you want the another web site view source use the HTTPWebRequest to get the response stream in c#.

Categories

Resources