HTML to PDF using Node.js and Express.js
Hey Geeks .... Hope you are doing well during this COVID-19 hard times. So, as a part of sharing and gaining knowledge activity, today we are going to show you how you can create pdf from a HTML template with dynamic value ?
Lets look at the brief index, what are we going to do to achieve this task ?
- We will create one RestAPI (POST) having parameter name and designation in body.
- We will have one ready simple HTML file which will be used to generate PDF file.
- We will test through Postman to test this flow.
Now, without wasting our time, lets head start to achieve this task.
[Step - 1] File/Folder Structure Initialization:
- Create folder to your desired directory. (I have create "nunjucks-example")
- Create "app.js" file inside this folder.
- Open cmd to newly created folder level.
- Run "npm init --yes" to create package.json file.
Did you notice something in last step ...? If you will do "npm init --yes" before create app.js file in that directory, then by default your main file would be "index.js". But if you want to create another file, like here I was willing to have "app.js" file as main file. So I created it first and then did "npm init --yes" .... I hope, you were aware about this thing (:-p)
[Step - 2] NPM Package Initialization
- Open cmd at created folder and install "express", "body-parser", "nunjucks" npm packages by following command.
npm install express body-parser nunjucks html-pdf --save
- Write below code to app.js file and create sample.html file at the level of app.js file.
Now, you need to run app.js file and check to postman that API is working fine or not.
Hope !!! It's working at your end as well. If you are facing any issue then contact us. We are happy to help you.. :-)

1 Comments
KING CASINO, LLC GIVES A $100 FREE BET
ReplyDeleteKING CASINO, LLC 출장샵 GIVES A $100 FREE BET to try. Visit https://septcasino.com/review/merit-casino/ us today herzamanindir.com/ and receive sol.edu.kg a $100 FREE BET! Sign up at our https://febcasino.com/review/merit-casino/ new site!
New Comment on MEAN Stack ...