Click here to Skip to main content
6,594,932 members and growing! (15,304 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate

Capture Entire Web Page

By daniel.esquivias

Capture an entire web page and save it as an image.
VB 8.0, Windows, .NETVS2005, Dev
Posted:5 Aug 2007
Updated:15 Aug 2007
Views:45,878
Bookmarked:86 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
25 votes for this article.
Popularity: 6.05 Rating: 4.33 out of 5
1 vote, 4.0%
1

2
2 votes, 8.0%
3
5 votes, 20.0%
4
17 votes, 68.0%
5


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


Member
esquivias.us
Location: United States United States

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
QuestionMultiple Pages TIFF Pinmemberdamifoo21:40 17 Mar '09  
GeneralHow can I read the screen text Pinmembermoreed21:30 10 Feb '09  
GeneralCan i plot this into asp.net web page? Pinmembercavinsnipes3:01 25 Sep '08  
Generaldoesn't convert big file Pinmembershob_sp2:24 16 Jun '08  
Generalhtml to image Pinmemberrejaneesh20:45 7 May '08  
GeneralNot capturing whole page Pinmemberjfarias6:45 6 May '08  
GeneralBeautiful! PinmemberDragon Soldier10:17 12 Nov '07  
QuestionUnhandled Exception ? PinmemberMadra Beag14:30 2 Oct '07  
AnswerRe: Unhandled Exception ? PinmemberNguyen Thanh Hai22:22 9 Nov '07  
Questionhow can i save source code of web page in word document Pinmemberskhurams22:02 14 Sep '07  
GeneralProblem with Popups & Fully loaded pages Pinmemberguilkerk9:34 17 Aug '07  
Generalwhat about web application? Pinmembercbattioli10:44 16 Aug '07  
GeneralLittle useful code PinmemberIrwan Hassan18:05 15 Aug '07  
GeneralRe: Little useful code PinmemberIrwan Hassan3:09 23 Aug '07  
QuestionHow to make it work if pages open within frames ? PinmemberVasanth Kumar17:25 14 Aug '07  
AnswerRe: How to make it work if pages open within frames ? PinmemberIrwan Hassan18:10 15 Aug '07  
GeneralNice code. PinmemberAndrewVos23:58 13 Aug '07  
GeneralI am interested in get page contents (Java) and recognize contents Pinmembersanong0:29 6 Aug '07  
GeneralHave a look at PinmemberSacha Barber0:02 6 Aug '07  
Generalcapturing actual page Pinmvptoxcct23:28 5 Aug '07  
GeneralRe: capturing actual page PinmemberAndrewVos0:01 14 Aug '07  
GeneralRe: capturing actual page Pinmembermichael. zhao1:15 7 Sep '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Aug 2007
Editor:
Copyright 2007 by daniel.esquivias
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project