How to create PDF document in Node.js ?
In this article we will see how to generate PDF document in NodeJS.
- Basic knowledge of Node.js.
- Node.js installed (version 12+).
- npm installed (version 6+).
Step 1: Install PDF module. The PDFkit– It is an Inbuilt Module for generating the PDF documents in the NodeJS in a very simpler and easy way in which we can make graphics, load images and also provide link of the website.
For installing it in the project write the following command on the terminal or command prompt.
npm install pdfkit
const PDFDocument = require('pdfkit'); const doc = new PDFDocument;
For adding new page in the PDF.
For saving PDF document in root directory.
Step 2: Installing Module for setting NodeJS environment. Also we need to configure the packahe.json file.
npm install express
Folder Structure: We can see that the PDF file is created in root directory.
Output: Created PDF file will look like this.