Skip to content
This repository has been archived by the owner on Dec 5, 2018. It is now read-only.

Not working #9

Closed
ashish314 opened this issue Jul 11, 2017 · 8 comments
Closed

Not working #9

ashish314 opened this issue Jul 11, 2017 · 8 comments

Comments

@ashish314
Copy link

ashish314 commented Jul 11, 2017

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
Copy link
Author

My bad, fixed it you can close it.

@Jonlee2001
Copy link

Jonlee2001 commented Nov 23, 2017

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

@ashish314
Copy link
Author

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

@sakadoddle
Copy link

sakadoddle commented Dec 14, 2017

Any idea how to solve this error?

@ashish314
Copy link
Author

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

@sakadoddle
Copy link

@ashish314 ya it works

@auvenshinec
Copy link

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

@sakadoddle
Copy link

sakadoddle commented Jan 26, 2018

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

@jblotus jblotus closed this as completed Dec 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants