To save webpage as image - c#

I have to save webpage as image by passing page URL,i have found one solution on this thread Convert webpage to image from ASP.NET[^] but it doesn't give me proper image(e.g. tried URL http://www.bugmuncher.com/).
Also tried HTML to Image in C#[^] but not able to deal with IViewObject interface ,basically not able to add reference to get this interface.
I have to do something like http://www.usersnap.com does.I made it work on FF,Chrome and IE9 by using canvas element which is unfortunately not supported by IE8.
Can i get proper working solution for my need???

i think you mean taking a screenshot.
Here you are a link about it.
Capture screenshot of active window?
But here i found on the site that just you want. Please check it.
Convert webpage to image from ASP.NET

The webpage can be saved as image by 2 methods.
1. Press ctrl+p
2. Select "Send to onenote" in print prompt window.
3. Press ok.
Now the image can be saved from the microsoft office -> microsoft onenotebook and rightclick on your content. save as the image file.
Second method is by using snapshot via snipping tool.

Related

Check if PDF viewer plugin is installed in IE/Chrome/FireFox/Safari

I am trying to create function that will essentially check if there is any PDF Viewer [Adobe or any other] is installed as Plugin for browser.
For example:
I someone click on link in webpage it will open up the PDF file instead of showing option to download, this means a PDF viewer plugin is present in browser.
I have my help on internet for this but none of them is with C# code.
Most of them is either JavaScript to check the plugins
others are there to check if Adobe PDF viewer is installed on the machine.
As a pure C# solution, I am not sure where you would want to run it, how would you go about using C# on a browser unless you are working server side? you can try the below as soon as you load your browser page and just save the details to the session variable if asp.net, then you always have a reference to the status of weather the plugin is installed or not.
You cant try a few ways to solve the issue, the first and simplest would be to just create a simple object tag
<object width="400" height="400" data="helloworld.pdf">
<p>Browser does not support PDF</p>
</object>
You can render this on a different page and just query if the control comes up or if the Browser does not support PDF message is shown,might as well just hide it, render it and then check it.
Or you could use the NavigatorPlugins that you can go through and find if there is anything related to PDF
You can check a reference to this SO answer

How to use print option C# selenium chrome driver

In my sample web page, there have print option. I need to call that,
<b> Print </b>
because I need to save above page as PDF(My major requirement is to save that page in PDF format). When I try to do it manually following popup window shows.
I need to do it through chrome C# selenium web driver. How can I do it? Please provide me sample code to solve this problem.
You'd use send keys to CTRL+P on the webpage then use driver find element by and then click
Send keys documentation found here:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.send?view=netframework-4.7.2
//This should work for clicking the save/print button without seeing your code I cannot test it.
driver.FindElement(By.XPath("//*[#id="button-strip"]/button[1]")).Click();
The print window is os realted component and you cannot automate them with selenium itself. You may need additional library to automate that along with your selenium code.
You are two Nuget package to it. One simply use InputSimulator and do key inputs like
Or
Automate browse window usings AutoITX nuget package.

problem with image display in visual studio

I have got a strange problem. Can somebody look into it please.
I have a folder called "img" in my website. I added a new image to it.
Now the strange problem is that when I give img/imagename.extension it doesn't display in the browser.
I have tried even ~/img. But ended nothing. Actually I am using the image in the spark template. I have taken an existing image and tried, it displays the existing image but not the one I have added. I was expecting may be I need to check in the newly added image but even doing that didn't end up the result.
Any ideas????
Thanks
if you using Razor use #Url.Content("~/img/yourimage.ext")
Check if authorisation rules of the folder img prevent the images from being shown e.g. to not authorised users.
Check if the image file was properly added to the solution in the VS.

ASP.NET screenshot page

Related Stack Overflow question is Programmatically get a screenshot of a page.
My users will be logged into a private system, and I want to have a button on the page that says "Take Screenshot". This will link into the support system, and when they take the screen shot, it creates a new ticket with the screen shot as an automatic attachment.
Content is variable, depending on who you are logged in as! This means I can't use an external screen shotting tool.
Ideally, I would like all the HTML to be rendered to a bitmap which is saved to a disk. Is there some sort of server-side Internet Explorer component that can render the HTML and save it as a BMP?
Kierren made good points. If I can grab the HTML via JavaScript, is there any server-side plugin that can render the HTML as an image as viewed through Internet Explorer?
I did some unsuccesful attempts with that in the past. I could not get the solution which works seemlessly but here are some I have had near-sucess (i.e. for most of the URLs) [Since I was doing POC, results did not matter] See if that helps
WebBrowser.DrawToBitmap() or other methods?
http://www.codeproject.com/KB/graphics/html2image.aspx
I have not heard of an HTML-to-bitmap converter before, but there are definitely HTML-to-PDF options,
http://www.htm2pdf.co.uk/
and
http://html-pdf-converter.com/
to name a couple.

how to download the image which will be displayed after a cache image on the web page?

I want to download an image from a cartoon website. and my app is WinForm,not WebForm.
So let's say that there is an image on the a.html.
Normally, when I click the previous page and am redirected to this page,
there will be a image :"image is loading",let's say A.jpg, in the same block.
After 5 seconds, the real one,let's say B.jpg, will be displayed.
So what I got is only the caching image rather than the one,B.jpg, which I want.
So..... how should I do it?
Thanks in advance.
ps: I have posted this qustion for more than 48 hours, and only got a few of answers which don't solve my problem.
I am wondering that why there are only 2 people posted their answers?
Is my question not clear?
If any, please let me know.
Thanks
EDIT: Original answer removed since I misunderstood the question entirely.
What you want to do is basically HTML scraping: using the actual html of the page to discover where files are hosted and download them. Because I'm not sure if there are any legal reasons that would prevent you from downloading the image files in this manner, I'm just going to outline an approach to doing this and not provide any working samples or anything. In other words, use this information at your own risk.
Using fiddler2 in Firefox, you should be able to find the domain and full url that one of the images is downloaded from. Basically just start fiddler2, navigate to the site in firefox, and then look for the biggest file that is downloaded. That will tell you exactly where the image is coming from.
Next, take a look at the HTML source code for the page you are viewing. The way this particular site works, it looks like it hides the previous/next downloads in a swf or something, but you can find the urls in the javascript for the page. Look for a javascript array called picArr.
To download these using a WinForms app, I would use the WebRequest object. Create a request for each image url and save the response to disk.

Categories

Resources