aws-lambda-wkhtmltopdf icon indicating copy to clipboard operation
aws-lambda-wkhtmltopdf copied to clipboard

Not working

Open ashish314 opened this issue 9 years ago • 8 comments

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.

ashish314 avatar Jul 11 '17 11:07 ashish314

My bad, fixed it you can close it.

ashish314 avatar Jul 11 '17 12:07 ashish314

@ashish314 I'm having the same problem - how did you fix it?? Jon5 Nevermind - for those interested please see closed issue #4

Jonlee2001 avatar Nov 23 '17 15:11 Jonlee2001

@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.

ashish314 avatar Nov 24 '17 06:11 ashish314

Any idea how to solve this error?

sakadoddle avatar Dec 14 '17 11:12 sakadoddle

@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 avatar Dec 18 '17 06:12 ashish314

@ashish314 ya it works

sakadoddle avatar Dec 20 '17 10:12 sakadoddle

@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 avatar Jan 19 '18 21:01 auvenshinec

@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.

sakadoddle avatar Jan 26 '18 08:01 sakadoddle