Not working
I tried as per your documentation, but it is not working { "errorMessage": "Cannot find module '/var/task/index'", "errorType": "Error", "stackTrace": [ "Function.Module._load (module.js:417:25)", "Module.require (module.js:497:17)", "require (internal/module.js:20:19)" ] }
Some help would be appreciated.
My bad, fixed it you can close it.
@ashish314 I'm having the same problem - how did you fix it?? Jon5 Nevermind - for those interested please see closed issue #4
@Jonlee2001 In Index.js there seems to be wrong usage of wkhtmltopdf, use it as shown below readStream = wkhtmltopdf(string,{optionsHere});
Means instead of callback it returns a readStream.
Any idea how to solve this error?
@rikee312
i have already mentioned the fix in my previous comment that fi works for me.
My previous comment below In Index.js there seems to be wrong usage of wkhtmltopdf, use it as shown below readStream = wkhtmltopdf(string,{optionsHere});
Means instead of callback it returns a readStream.
@ashish314 ya it works
@ashish314 @rikee312
Can either of you please provide example code that you got working with readStream = wkhtmltopdf(string,{optionsHere});. I am running into the same issue and struggling with the correct usage of wkhtmltopdf in this context.
Thank you.
@auvenshinec
'use strict';
process.env['PATH'] =
process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];
const wkhtmltopdf = require('wkhtmltopdf');
const MemoryStream = require('memorystream');
const { createResponse } = require('../utils/create-response');
module.exports.index = (event, context, callback) => {
let content = JSON.parse(event.body);
let html = content.html;
var memStream = new MemoryStream();
var html_utf8 = new Buffer(html, 'base64').toString('utf8');
const options = {
pageSize: 'letter'
};
wkhtmltopdf(html_utf8, options, function(code, signal) {
callback(
null,
createResponse(200, { pdf_base64: memStream.read().toString('base64') })
);
}).pipe(memStream);
};
this is the working code for me.