Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving a web page as image

As a hobby project I am exploring the ways to save a web page (HTML) as image, mostly programatically using c/c++/javascript/java. Till now I have come across the following ways:

  1. Get the IHTMLElement of page body and use it to query for IHTMLElementRender and then use its DrawToDC method (Ref: http://www.codeproject.com/KB/IP/htmlimagecapture.aspx ). But the problem is that it did not work for all the pages (mostly pages having embedded iframes).

  2. Another way which i can think of is to use some web browser component and when the pages is fully loaded then capture it using BitBlt (Ref: http://msdn.microsoft.com/en-us/library/dd183370%28VS.85%29.aspx ). But the problem is that the page I have requested may be longer than my screen size and it will not fit into the web browser component.

Any direction/suggestion to resolve above issues or an alternative approach is greatly appreciated.

like image 573
Favonius Avatar asked Nov 09 '10 04:11

Favonius


1 Answers

If you use Python, there's pywebshot and webkit2png. Both of them have some dependencies, though.

Edit: Oops, Python is not in your list of preferred languages. I'll leave this answer here anyway, because you said "mostly" and not "exclusively".

like image 171
kijin Avatar answered Sep 28 '22 18:09

kijin