0

I have this code that generated PDF file:

async function toPDFile(file) {
  let done = await libreConvert(file, '.pdf', undefined);
  return done
}

toPDFile(templateFile).then(successCallback, failureCallback);

function successCallback(result) {
  console.log(result);
}

function failureCallback(error) {
  console.log(error);
}

console.log(result) returns Buffer but when I assign it to var it returns undefined. How can I just get value like a normal human being?

xDololow
  • 29
  • 4
  • 2
    "console.log(result) returns Buffer but when I assign it to var it returns undefined" - would you share some more code, please? The "when I assign it to var it returns undefined" piece. – mbojko Oct 03 '21 at 14:43
  • by "console.log(result) returns Buffer but when I assign it to var it returns undefined", you mean you used `const buf = console.log(result)`? Then for sure it is `undefined`. You actually meant to say, "console.log(result) prints out a Buffer object" – nonopolarity Oct 03 '21 at 14:46
  • @nonopolarity no i make `var pdf;` outside callback and assign inside it like this `pdf = result` and it gives undefined. – xDololow Oct 03 '21 at 16:31
  • @xDololow Well [that can't work](https://stackoverflow.com/q/23667086/1048572). Just use the `result` variable *inside* the `successCallback`! Use `await` where you were calling `toPDFile` – Bergi Oct 03 '21 at 17:20

0 Answers0