【问题标题】:libreoffice-convert not working in nodejslibreoffice-convert 在 nodejs 中不起作用
【发布时间】:2020-11-12 20:11:37
【问题描述】:

所以,我使用的是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 上运行它。

【问题讨论】:

  • 你能从C:\Program Files\LibreOffice\program 运行soffice.exe 吗?有用吗?
  • 是的,我可以运行soffice.exe。它工作得很好。
  • 而且bootstrap.ini 看起来也不错?
  • 啊,是的,我已经更新了问题并包含了我的bootstrap.ini 的内容。
  • @Anatoly,在 Mac 上安装 LibreOffice 后非常简单,一切正常。但在 Windows 上,这发生了。

标签: node.js libreoffice


【解决方案1】:

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

【讨论】:

  • 它对我有用,谢谢
【解决方案2】:

libreoffice-convert 中存在一个已知问题,它仍处于Open 状态:issue。您可以从本期 cmets 的讨论中尝试解决方法

【讨论】:

    【解决方案3】:

    如果有人遇到和我一样的问题,我就是这样做的。

    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. 立即尝试您的脚本。

    【讨论】:

      【解决方案4】:

      这对我有用:

      安装:yum install libreoffice-headless

      Reference

      【讨论】:

        猜你喜欢
        • 2015-08-01
        • 2021-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多