Posted on Arjun

Create WebPage Screenshots with Node.js and PhantomJS

To create webpage screenshots we are going to use PhantomJs. PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG. in simple terms, PhantomJS is a web browser without a graphical user interface.

Assuming you’ve downloaded and installed PhatomJS, create a JavaScript file (screenshot.js for example) with the following contents:

Running this snippet from a web-browser won’t work, we need to load this script using PhantomJS.so run the script from command line.

That’s all it, you should see a file in the same path as screenshot.js named arjunphp.png, open it and you should see a full page screenshot of arjunphp.com. We could save the page as a PDF document, JPEG, PNG, and GIF.

Out of the box PhantomJS provides configurable options for screen capturing. You can find the all available settings at – http://phantomjs.org/api/webpage/property/settings.html

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
DMCA.com Protection Status