Closed SCHrodrigo closed 3 years ago
@SCHrodrigo Is libreoffice installed on your linux server? What's the output of which soffice
?
@elwerene I used "npm i libreoffice-convert --save" to install it in the directory with index.js, which runs the server.
The output to which soffice
were:
$ sudo which soffice which: no soffice in (/sbin:/bin:/usr/sbin:/usr/bin) $ which soffice /usr/bin/which: no soffice in (/home/ec2-user/.local/opt/node/bin:/home/ec2-user/.local/bin:/home/ec2-user/.nvm/versions/node/v14.9.0/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin)
Both command were executed inside the dir with index.js.
@SCHrodrigo Please install libreoffice as statet in the Readme. This library only works with a preinstalled instance of libreoffice. If that's not an option on your server, then this lib won't help you convert files. Sorry
Hey, so I just got libreoffice installed, the message from which soffice
is
/opt/libreoffice7.0/program/soffice
I confirmed there is a file soffice and soffice.bin, but the Could not find soffice binary
error persists.
Sorry for dragging this.
@SCHrodrigo no worries, soffice needs to be in "/usr/bin/soffice". you could link it there:
ln -s /opt/libreoffice7.0/program/soffice /usr/bin/soffice
There's an issue to set another installation folder, but nobody actually provided a pr for it yet: https://github.com/elwerene/libreoffice-convert/issues/49
Hot damn, it worked! Thank you so much for helping!
i have the same error.
i installed libre and nodejs on same container service
here is my express js code on app.js file
const libre = require('libreoffice-convert');
const {fi} = require("@faker-js/faker");
libre.convertAsync = require('util').promisify(libre.convert);
app.post("/upload-dokumen",
async (req, res) => {
const ext = '.pdf'
const inputPath = path.resolve(__dirname, './resources/example.txt');
const outputPath = path.resolve(__dirname, `/resources/example${ext}`);
const file =fs.readFileSync(inputPath);
libre.convert(file,ext, undefined, function (err, done){
fs.writeFileSync(outputPath, done);
res.json({
message: 'express js boilerplate',
text: 'upload dokumen',
data: {
path: outputPath
}
});
});
}
);
fixed after change from path.resolve to join
const inputPath = path.join(__dirname, './resources/example.docx');
const outputPath = path.join(__dirname, `/resources/example${ext}`);
As in the title, there is something going on that the "done" variable is coming up short.
I'm on Linux, using node express to host an API to convert a docx that is generated with docxtemplater based on the answers of a form.
This is the code that is converting:
fs.writeFileSync(path.resolve(__dirname,
/home/ec2-user/oficial_formulario/documentos/Prospeccao/${nome_docx}.docx`), buf);And this is the error coming up:
The first console.log on the code shows the file being converted, so I don't know what's going on.