0

I need to convert a docx file to pdf but I don't know very well nodejs, however, I know that the following can be done:

There is a project called unoconv-worker and in it, there is a part where the following line appears:

  var child = spawn ('unoconv', [
    '--stdout',
    '--no-launch',
    '--format', job.outputExtension,
    job.tempPath
]);

https://github.com/koumoul-dev/unoconv-worker/blob/master/route.js

In my terminal I can convert it in the following way and it works perfectly:

unoconv -f pdf --output="something.pdf" docxtoconvert.docx

However, I would like to give you a file that I gave you the route, so I tried it this way:

var filePath = "/tmp/docxtoconvert.docx";
var child = spawn ("unoconv", [
  "-f",
  "pdf",
  "--output",
  "/tmp/something.pdf",
  filePath

]);

Output:

Unoconv converter received message on stderr function () {
  if (arguments.length === 0) {
    var result = this.utf8Slice(0, this.length);
  } else {
    var result = slowToString.apply(this, arguments);
  }
  if (result === undefined)
    throw new Error('toString failed');
  return result;
}

But it has not worked. Could you help me? Thank you

  • Try by giving the absolute path to `unoconv` – Tudor Constantin Oct 27 '18 at 11:00
  • The unoconv is in the environment variable. In fact, if I run the normal project, that is, as it is by default, it works correctly, without going through the absolute path of unoconv – yirdebagne Oct 27 '18 at 11:17
  • yeah, but that's because you call it from your terminal session (I guess `bash`), whereas the nodejs session might not be configured the same way as the bash one. That's why I suggest you to try providing the full path to the unoconv in your script. – Tudor Constantin Oct 27 '18 at 11:24
  • Same error, despite putting the full path of oneconv: Unoconv converter received message on stderr function () { if (arguments.length === 0) { var result = this.utf8Slice(0, this.length); } else { var result = slowToString.apply(this, arguments); } if (result === undefined) throw new Error('toString failed'); return result; – yirdebagne Oct 27 '18 at 11:35

1 Answers1

0

Lot of wrapper modules exists for unoconv that can solve your problem.

You can try this https://www.npmjs.com/package/unoconv

Alok
  • 7,734
  • 8
  • 55
  • 100