JS
Node JS
How To Create PDF File In Node JS?
Now, let's see example of how to create pdf file using node js. you'll learn node js generate pdf file. step by step explain node js create pdf file. i would like to show you node.js create pdf file using pdfkit. Follow bellow tutorial step of node.js pdfkit example.
- TAGS
- Node JS
- 4.5/5.0
- Last updated 08 September, 2022
- By Admin
Here, i will give you simple example of how to generate pdf file in node.js. we will use pdfkit npm package to create pdf file. you can follow bellow step and see creating new pdf file with text and image.
Step 1: Create Node App
run bellow command and create node app
mkdir my-app cd my-app npm init
Install Express using bellow command:
npm install express --save
Install pdfkit using bellow command:
npm install pdfkit --save
Step 2: Create server.js file
Here, make sure you have "uploads" folder and one image name with node-js-file-size.png.
server.js
const PDFDocument = require('pdfkit'); var fs = require('fs'); const doc = new PDFDocument(); doc.pipe(fs.createWriteStream('it-example.pdf')); doc.fontSize(27) .text('This is example from codewale.com', 100, 100); doc.image('uploads/node-js-file-size.png', { fit: [400, 400], align: 'center', valign: 'center' }); doc.addPage() .fontSize(15) .text('Generating PDF with the help of pdfkit npm', 100, 100); doc.addPage() .fillColor('blue') .text('The link for codewale.com website', 100, 100) .link(100, 100, 160, 27, 'https://www.codewale.com/'); doc.end();
now you can simply run by following command:
node server.js
I hope it can help you...
Categories
PHP
(5)
Codeigniter
(5)
Laravel
(3)
JS
(1)
Angular JS
(5)
Node JS
(5)
Vue JS
(4)
React JS
(6)
jQuery
(5)
Javascript
(3)
jQuery UI
(6)
Wordpress
(1)
Python
(5)
Database
(1)
MySql
(5)
Mongo DB
(1)
DBMS
(1)
SQL
(5)
HTML
(1)
HTML 5
(5)
CSS
(5)
Bootstrap
(5)
Ajax
(5)
JAVA
(1)
JSON
(5)
Ubuntu
(5)
Server
(5)
Git
(3)
Google
(1)
Google Map
(7)
Google API
(1)
Elastic Search
(1)
Apache
(1)
Installation
(1)