Saturday, 15 October 2016

How to create a webpage screenshot with NodeJs and PhantomJS

To create webpage screenshots we are using PhantomJs. PhantomJS is a headless WebKit scriptable with a JavaScript API. It has very fast and native support for various web standards like DOM handling, CSS selector, JSON, Canvas, and SVG. In simple words PhantomJS is a web browser without a graphical user interface.Assuming you already downloaded and installed PhatomJS, create a JavaScript file (capturescreen.js) with the following contents.

Phantom



var wpage = require('webpage').create();

wpage.open('http://wantcode.in/', function() {
    wpage.render('wantcode.png');
    phantom.exit();
});

Then you need to run this script in browser it won't work. you need to run in command line.


phantomjs capturescreen.js

After running this see in the same folder a png file is create of screenshot.For more option you can read the phantomJs here.Please feel free to comment below for suggestions and problems.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts