forked from jblotus/aws-lambda-wkhtmltopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
25 lines (23 loc) · 804 Bytes
/
index.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
var wkhtmltopdf = require('wkhtmltopdf');
var MemoryStream = require('memorystream');
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];
exports.handler = function(event, context, callback) {
var body = JSON.parse(event.body);
var memStream = new MemoryStream();
var content;
if (body.htmlBase64 != null) {
content = new Buffer(body.htmlBase64, 'base64').toString('utf8');
} else {
content = body.url;
}
wkhtmltopdf(content, body.options, function(code, signal) {
const response = {
statusCode: 200,
body: JSON.stringify({
pdfBase64: memStream.read().toString('base64'),
options: body.options
})
};
callback(null, response);
}).pipe(memStream);
};