如何解决libreoffice-convert在nodejs中不起作用
因此,我正在使用libreoffice-convert,它当然在我的nodejs应用程序中运行。 我的代码如下
const file = fs.readFileSync(enterPath);
// Convert it to pdf format with undefined filter (see Libreoffice doc about filter)
libre.convert(file,extend,undefined,(err,done) => {
if (err) {
console.log(`Error converting file: ${err}`);
}
// Here in done you have pdf file which you can save or transfer in another stream
fs.writeFileSync(outputPath,done);
});
上面的代码在尝试打开LibreOffice时返回错误。
The application cannot be started.
The configuration file "C:\Program Files\LibreOffice\program\bootstrap.ini" is corrupt.
这是我的bootstrap.ini
[Bootstrap]
InstallMode=<installmode>
ProductKey=LibreOffice 7.0
UserInstallation=$SYSUSERCONFIG/LibreOffice/4
如果有人可以帮助解决此问题,请多谢。同样不确定是否有帮助,但是我正在Windows上运行它。
解决方法
libreoffice-convert
中存在一个已知问题,但仍处于Open
状态:issue。您可以在此问题评论的讨论中尝试解决方法
在 libreoffice-convert/index.js 中做以下更改
// change
let command = `${results.soffice} -env:UserInstallation=file://${installDir.name} --headless --convert-to ${format}`;
// to
let command = `${results.soffice} --headless --convert-to ${format}`;
,
如果有人遇到和我一样的问题,这就是我为解决它所做的。
- 下载并安装 LibreOffice。你可以下载它here
- 运行
npm i libreoffice-convert
后,转到your_project/node_modules/libreoffice-convert/index.js
,找到下面的代码。
/* your_project/node_modules/libreoffice-convert/index.js */
let command = `-env:UserInstallation=file://${installDir.name} --headless --convert-to ${format}`;
// change to
let command = `${installDir.name} --headless --convert-to ${format}`;
- 立即尝试您的脚本。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。