[英]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:我需要将 docx 文件转换为 pdf 但我不太了解 nodejs,但是,我知道可以执行以下操作:
There is a project called unoconv-worker and in it, there is a part where the following line appears:有一个名为 unoconv-worker 的项目,其中有一部分出现以下行:
var child = spawn ('unoconv', [
'--stdout',
'--no-launch',
'--format', job.outputExtension,
job.tempPath
]);
https://github.com/koumoul-dev/unoconv-worker/blob/master/route.js 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. unoconv 存在许多包装器模块,可以解决您的问题。
You can try this https://www.npmjs.com/package/unoconv你可以试试这个https://www.npmjs.com/package/unoconv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.