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}`;
,

如果有人遇到和我一样的问题,这就是我为解决它所做的。

  1. 下载并安装 LibreOffice。你可以下载它here
  1. 运行 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}`;

  1. 立即尝试您的脚本。