-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathhtmlPdfNode.js
More file actions
29 lines (28 loc) · 1.15 KB
/
htmlPdfNode.js
File metadata and controls
29 lines (28 loc) · 1.15 KB
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
htmlPdfNode = (req, res) => {
try {
const body = req.body
let requiredParams = ["html"];
let verifiedData = global.verifyParams(requiredParams, body);
if (!verifiedData.success) {
return (global.responseFunction(res, verifiedData.statusCode, verifiedData));
}
htmlTopdfNode.generatePdf({ content: body.html }, { format: 'A4' }).then(pdfBuffer => {
if(pdfBuffer){
global.responseFunction(res, 200, {"message": "Verified data successfully", "data": Buffer.from(pdfBuffer).toString('base64'), "success":true});
}else{
global.responseFunction(res, 400, {"message": "Error In converting Html to PDF", "success":false});
}
}).catch(err=>{
global.responseFunction(res, 400, {"message": "Error In converting Html to PDF", "data": err, "success":false});
});
} catch (err) {
return (global.responseFunction(res,
500, {
"success": false,
"statusCode": 500,
"message": "Something went wrong",
"data": err
}
))
}
};