On 08/01/2011 05:12 PM, ashu.soman wrote:
How can one take a snapshot of a page or convert page into an image?

The way that Taha mentioned works by using a library that will download the HTML and will try to render it to PDF. There are various such libraries. Such renderers can't do magic, so the success depends on the complexity of the popup web page (frames, divs, objects, flash?).

If that is good enough and the web page is simple, than you are OK.

But if it's a complex page, or you are building some cataloging site or CMS which needs to store many bookmarks and grab snapshots for each bookmark, and you are not in control of the remote web sites and their complexity, than the only solution is to run a full browser in the background, like a service, and make it do the snapshots to files.

On linux it is possible for example to run Firefox headless ( in the background in a virtual XWindows - with the GUI sent to a virtual screen frame buffer) and you can have it open any web page, render it in the virtual buffer and then you can read the contents of the virtual screen and convert it to an image file. And it will look exactly as if you were on the desktop on that computer, surfing with Firefox.

The problem with this is that you need to have enough privileges on the server to be able to setup the environment, and it will need lot of RAM for each process (as much RAM as the browser itself needs to open and more depending on the page complexity), and you will have to make custom shell scripts on the server that will invoke the browser in the background with the right options to save the output to a file.

Search on google: firefox headless

There are many guides how to do this, and here is just one random link from the search:
http://www.unruhdesigns.com/blog/2010/10/using-firefox-on-a-headless-server-to-make-screenshots-aof-websites

Just a note, in case someone needs to do staff like this, in a similar way you can even run Libreoffice on a headless X server, and for example use it as a service to render DOC to PDF, or convert documents from one type to another, execute macro-s on documents, etc...

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to