-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_generator.js
42 lines (33 loc) · 917 Bytes
/
pdf_generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// const http= require('http');
// const fs = require('fs');
// const server= http.createServer();
// server.on('request', (req,res)=>{
// if(req.url =='/')
// {
// file =` <h1> HOME IS BACK hii</h1> `;
// res.end(file);
// }
// else if(req.url=="/aman")
// {
// let file= fs.readFileSync('./aman.html');
// res.writeHead(200,{"content-type":'Text/html'})
// res.end(file) ;
// }
// }
// );
// server.listen(5000);
// ...............SECOND STEP .........
var express = require('express'),
app = express(),
pdf = require('express-pdf');
path= require('path');
//previously app.use(pdf())
app.use(pdf); // or you can app.use(require('express-pdf'));
app.use(express.static('public'));
app.use('/', function(req, res){
res.pdfFromHTML({
filename: 'generated.pdf',
html: path.resolve(__dirname, 'demo.html'),
});
});
app.listen(5000);