Click here to Skip to main content
Licence 
First Posted 5 Aug 2007
Views 76,969
Downloads 3,212
Bookmarked 107 times

Capture Entire Web Page

By | 15 Aug 2007 | Article
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

About the Author

daniel.esquivias



United States United States

Member

esquivias.us

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionVERY SKINNY Image created PinmemberRon Mittelman9:33 25 Oct '11  
AnswerRe: VERY SKINNY Image created PinmemberRon Mittelman9:55 25 Oct '11  
GeneralDoesn't seem to work on a page with JScript or ActiveX PinmemberSteve Dunn7:37 22 Jun '10  
GeneralProblem with DrawToBitmap Pinmemberchurchillr9:36 22 Apr '10  
QuestionMultiple Pages TIFF Pinmemberdamifoo20:40 17 Mar '09  
QuestionHow can I read the screen text Pinmembermoreed20:30 10 Feb '09  
QuestionCan i plot this into asp.net web page? Pinmembercavinsnipes2:01 25 Sep '08  
Generaldoesn't convert big file Pinmembershob_sp1:24 16 Jun '08  
Generalhtml to image Pinmemberrejaneesh19:45 7 May '08  
GeneralNot capturing whole page Pinmemberjfarias5:45 6 May '08  
GeneralBeautiful! PinmemberDragon Soldier9:17 12 Nov '07  
I have been Googling all morning for something like this! Great Work, simple to use, and absolutely fantastic job!
QuestionUnhandled Exception ? PinmemberMadra Beag13:30 2 Oct '07  
AnswerRe: Unhandled Exception ? PinmemberNguyen Thanh Hai21:22 9 Nov '07  
Questionhow can i save source code of web page in word document Pinmemberskhurams21:02 14 Sep '07  
GeneralProblem with Popups & Fully loaded pages Pinmemberguilkerk8:34 17 Aug '07  
Questionwhat about web application? Pinmembercbattioli9:44 16 Aug '07  
GeneralLittle useful code PinmemberIrwan Hassan17:05 15 Aug '07  
GeneralRe: Little useful code PinmemberIrwan Hassan2:09 23 Aug '07  
QuestionHow to make it work if pages open within frames ? PinmemberVasanth Kumar16:25 14 Aug '07  
AnswerRe: How to make it work if pages open within frames ? PinmemberIrwan Hassan17:10 15 Aug '07  
GeneralNice code. PinmemberAndrewVos22:58 13 Aug '07  
GeneralI am interested in get page contents (Java) and recognize contents Pinmembersanong23:29 5 Aug '07  
GeneralHave a look at PinmemberSacha Barber23:02 5 Aug '07  
Generalcapturing actual page Pinmvptoxcct22:28 5 Aug '07  
GeneralRe: capturing actual page PinmemberAndrewVos23:01 13 Aug '07  

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.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120529.1 | Last Updated 16 Aug 2007
Article Copyright 2007 by daniel.esquivias
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid