How to generate PDF of a website page with Node.js


In this article, we will see how easy it is to generate PDF of any webpage using Nodejs and send the generated pdf back to the client side application


Step 1
$ npm install -g html-pdf

Nodejs Code example for Creating PDF of web Page

var fs = require('fs'); var pdf = require('html-pdf'); var html = fs.readFileSync('./mybus.html', 'utf8'); var options = { format: 'Letter' }; pdf.create(html, options).toFile('./mybus.pdf', function(err, res) { if (err) return console.log(err); console.log(res); // { filename: '/app/mybus.pdf' } });
//mybus.html can replace with any html file. according to your application.

Comments

Popular posts from this blog

What is HTML? Complete Beginner’s Guide (with Examples)

HTML Forms — Input, Label, Button & Validation (Explained Like a Teacher With Examples)

Difference Between HTML and HTML5 (2025 Explained) | Features, Advantages & Comparison Table