Hello All,

Today, I am going to explain how to convert the HTML to PDF in grails using Phantom JS.

Let’s start coding and follow the below steps.

1. I am going to use ubuntu operating system.

2. Install the PhantomJs on your computer. use below command :

sudo apt-get install phantomjs

3. We will also need the phantomjs script rasterize.js  for  converting the HTML to pdf. copy the rasterize.js from the (http://phantomjs.org) and paste any location of your computer or you can copy the js file below URL. 


4. We have completed all the pre-requirement step in achieving the objective.(HTML to PDF).

5. Write the code in our controller with the name convertHtmlToPdf() action.

6. Now, after hitting the convertHtmlToPdf()action, automatically pdf file will download.

I have followed this URL: http://phantomjs.org/examples

Hope you will find this helpful.