How to use PhantomJS as a PDF Convertor?

In the previous blog we have installed PhantomJS in our local system now we will see how to use PhantomJS as PDF convertor.

As we know PhantomJS is a web browser so it has a rendering engine which will render HTML  page directly into many forms like PNG, PDF.

First we will see how to take Screenshot of a HTML page into PNG format.

Here we will render the HTML page into PNG file with the help of PhantomJS Engine.



If you don't want to type you can directly copy paste the code from below:


var page = require('webpage').create();
page.open('http://google.com/', function() {
  page.render('google.png');
  console.log("Success");
  phantom.exit();
});


Place the above code in a Javascript file and save this file at the same location where you saved PhantomJS like google.js.

Open command prompt  go to the location where you have placed Phantomjs.




Now run the Javascript file you made into PhantomJS engine.




If Success is printed in the console the  you can find the PNG file created at the same location.






Preview of Screenshot Created:




In the next Blog we will see how to use PhantomJS as PDF Convertor for HTML file.

Related Posts: 

https://amanvyas.blogspot.in/2017/05/how-to-use-rasterizejs-with-phantomjs.html

https://amanvyas.blogspot.in/2017/05/how-to-install-phantomjs-in-windows-as.html

For more updates please subscribe my blog.

Comments

Popular Posts

How to use Rasterize.js with PhantomJS?

How to Crack any Government exam in 6 months?

A brief Introduction of CSS Box Model

Total Pageviews