简体   繁体   中英

How to convert a PDF file with NodeJS + Unoconv

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM