5,693,062 members and growing! (15,871 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, VB, Windows, .NETVisual Studio, VS2005, Dev

Posted: 5 Aug 2007
Updated: 15 Aug 2007
Views: 28,149
Bookmarked: 66 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
24 votes for this Article.
Popularity: 5.96 Rating: 4.32 out of 5
1 vote, 4.2%
1
0 votes, 0.0%
2
2 votes, 8.3%
3
5 votes, 20.8%
4
16 votes, 66.7%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article


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


esquivias.us
Location: United States United States

Other popular VB.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 20 of 20 (Total in Forum: 20) (Refresh)FirstPrevNext
GeneralCan i plot this into asp.net web page?membercavinsnipes3:01 25 Sep '08  
Generaldoesn't convert big filemembershob_sp2:24 16 Jun '08  
Generalhtml to imagememberrejaneesh20:45 7 May '08  
GeneralNot capturing whole pagememberjfarias6:45 6 May '08  
GeneralBeautiful!memberDragon Soldier10:17 12 Nov '07  
QuestionUnhandled Exception ?memberMadra Beag14:30 2 Oct '07  
AnswerRe: Unhandled Exception ?memberNguyen Thanh Hai22:22 9 Nov '07  
Questionhow can i save source code of web page in word documentmemberskhurams22:02 14 Sep '07  
GeneralProblem with Popups & Fully loaded pagesmemberguilkerk9:34 17 Aug '07  
Generalwhat about web application?membercbattioli10:44 16 Aug '07  
GeneralLittle useful codememberIrwan Hassan18:05 15 Aug '07  
GeneralRe: Little useful codememberIrwan Hassan3:09 23 Aug '07  
QuestionHow to make it work if pages open within frames ?memberVasanth Kumar17:25 14 Aug '07  
AnswerRe: How to make it work if pages open within frames ?memberIrwan Hassan18:10 15 Aug '07  
GeneralNice code.memberAndrewVos23:58 13 Aug '07  
GeneralI am interested in get page contents (Java) and recognize contentsmembersanong0:29 6 Aug '07  
GeneralHave a look atmemberSacha Barber0:02 6 Aug '07  
Generalcapturing actual pagemvptoxcct23:28 5 Aug '07  
GeneralRe: capturing actual pagememberAndrewVos0:01 14 Aug '07  
GeneralRe: capturing actual pagemembermichael. 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-2008
Web13 | Advertise on the Code Project