Click here to Skip to main content
Click here to Skip to main content
Go to top

Capture Entire Web Page

, 15 Aug 2007
Rate this:
Please Sign up or sign in to vote.
Capture an entire web page and save it as an image.


Screenshot - gui2_animated.gif

Update

- 08.15.2007 - user defined image formats, save path, base file name, text overlay/watermark, and screen res guidelines... and some other ideas to implement.

Introduction

I have seen other articles that describe how to accomplish this, but had no luck in getting any to work with Internet Explorer 7. This is a simple example that captures a webpage, inlcuding elements below the fold, and saves it as an image. Here is what to expect:

Screenshot - httpwwwcodeprojectcom.png
Note that this has been resized, captured images are actual size.

Using the code

This example includes only the basics. Images are saved as PNG's in the same directory as the exe. Saving as a different image format, variable pausing, and given filename should be relatively easy to add.

Private Sub GetImage()
    If WebBrowser1.Document Is Nothing Then
        Return
    End If
    Try
        Dim scrollWidth As Integer
        Dim scrollHeight As Integer
        scrollHeight = WebBrowser1.Document.Body.ScrollRectangle.Height
        scrollWidth = WebBrowser1.Document.Body.ScrollRectangle.Width
        WebBrowser1.Size = New Size(scrollWidth, scrollHeight)
        Dim bm As New Bitmap(scrollWidth, scrollHeight)
        WebBrowser1.DrawToBitmap(bm, New Rectangle(0, 0, bm.Width, bm.Height))
        Dim SaveAsName As String
        SaveAsName = Regex.Replace(textWebURL.Text, "(\\|\/|\:|\*|\?|\""|\<|\>|\|)?", "")
        bm.Save(SaveAsName & ".png", System.Drawing.Imaging.ImageFormat.Png)
        bm.Dispose()
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
        '
    End Try
    buttonCapture.Enabled = True
End Sub

Points of Interest

Waiting a second or two after the document has loaded will allow that much more of the client-side animation / js / etc. to be captured. If the web page is saved as a "white" image, try the above.

Environment

Vista / VS2005

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author


Comments and Discussions

 
GeneralMy vote of 5 PinmemberS.H.Yadegari6-Sep-13 1:55 
QuestionVERY SKINNY Image created PinmemberRon Mittelman25-Oct-11 9:33 
AnswerRe: VERY SKINNY Image created PinmemberRon Mittelman25-Oct-11 9:55 
GeneralDoesn't seem to work on a page with JScript or ActiveX PinmemberSteve Dunn22-Jun-10 7:37 
GeneralProblem with DrawToBitmap Pinmemberchurchillr22-Apr-10 9:36 
I've been working on a similar project, and have found a couple of solutions. But neither of them is 100% reliable.
 
Problem #1: WebBrowser.DrawToBitmap
Fails to render bitmap for some sites (yahoo, paypal, etc.) This is a known problem, which Microsoft says it will not fix because DrawToBitmap is not actually a public member of the bitmap class.
Therefore, DrawToBitmap is not a viable solution for a commercial-level product.
 
Problem #2: Graphics.CopyFromScreen
This method works great for creating Thumbnails, but it is not capable of capturing full-sized screenshots. CopyFromScreen will only capture the content which is visible on the screen. If the page requires scrolling, or is partially obscured it will not render that portion of the image.
 
At this point, I'm looking into a solution that implements the appropriate WIN32 API calls, as the .net framework doesn't seem to have the power to accomplish this task in a reliable fashion.
QuestionMultiple Pages TIFF Pinmemberdamifoo17-Mar-09 20:40 
QuestionHow can I read the screen text Pinmembermoreed10-Feb-09 20:30 
QuestionCan i plot this into asp.net web page? Pinmembercavinsnipes25-Sep-08 2:01 
Generaldoesn't convert big file Pinmembershob_sp16-Jun-08 1:24 
Generalhtml to image Pinmemberrejaneesh7-May-08 19:45 
GeneralNot capturing whole page Pinmemberjfarias6-May-08 5:45 
GeneralBeautiful! PinmemberDragon Soldier12-Nov-07 9:17 
QuestionUnhandled Exception ? PinmemberMadra Beag2-Oct-07 13:30 
AnswerRe: Unhandled Exception ? PinmemberNguyen Thanh Hai9-Nov-07 21:22 
Questionhow can i save source code of web page in word document Pinmemberskhurams14-Sep-07 21:02 
GeneralProblem with Popups & Fully loaded pages Pinmemberguilkerk17-Aug-07 8:34 
Questionwhat about web application? Pinmembercbattioli16-Aug-07 9:44 
GeneralLittle useful code PinmemberIrwan Hassan15-Aug-07 17:05 
GeneralRe: Little useful code PinmemberIrwan Hassan23-Aug-07 2:09 
QuestionHow to make it work if pages open within frames ? PinmemberVasanth Kumar14-Aug-07 16:25 
AnswerRe: How to make it work if pages open within frames ? PinmemberIrwan Hassan15-Aug-07 17:10 
GeneralNice code. PinmemberAndrewVos13-Aug-07 22:58 
GeneralI am interested in get page contents (Java) and recognize contents Pinmembersanong5-Aug-07 23:29 
GeneralHave a look at PinmemberSacha Barber5-Aug-07 23:02 
Generalcapturing actual page Pinmvptoxcct5-Aug-07 22:28 
GeneralRe: capturing actual page PinmemberAndrewVos13-Aug-07 23:01 
GeneralRe: capturing actual page Pinmembermichael. zhao7-Sep-07 0:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 16 Aug 2007
Article Copyright 2007 by daniel.esquivias
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid