Closed kennylbj closed 2 years ago
what happens if you run soffice.exe with th the same convert arguments as it is called with this lib?
I manually remove -env:UserInstallation=file://${installDir.name}
in index.js and everything work well again.
// change
let command = `${results.soffice} -env:UserInstallation=file://${installDir.name} --headless --convert-to ${format}`;
// to
let command = `${results.soffice} --headless --convert-to ${format}`;
I don't know what happened under the hood but it actually works. what's the meaning of -env argument?
installDir.name
is not a valid POSIX format which is expected by the binary. Converting the dir to POSIX fixes that issue:
// line 16
const posixInstallDir = installDir.name.split(path.sep).join(path.posix.sep);
// line 49
let command = `-env:UserInstallation=file://${posixInstallDir} --headless --convert-to ${format}`;
From Pull-request https://github.com/elwerene/libreoffice-convert/pull/47#issuecomment-724867127
@ilkohoffmann Doesn't this break on windows? In the documentation it says, the
path.sep
is\
in windows which is correct as far as I know. You replace it withpath.posix.sep
which should always be/
- I can't test it on Windows as I don't have access to a installation. Or did I miss a change in Windows path behavior and it now accepts/
?
Not changing the \
to /
causes a break on windows. Without the change the resulting command looks like this:
// line 50
`soffice.exe -env:UserInstallation=file://C:\Users\<USER>\AppData\Local\Temp\soffice-5568-<XXXX>`
causing the error @kennylbj mentioned above. I couldn´t find any good documentation to the headless soffice converter and the available parameterization. I believe that the -env
parameter expects a posix compliant format rather than a windows path expression because its handled internally. I have tested it on windows and it seems to work now. The path is created on the corresponding tmp location and removed after succesful execution. I have closed the pull request anyway, because their is another change to make on windows and I am not sure if that will still work on unix-based systems. The expression with two trailing slashes after file
// line 50
let command = `-env:UserInstallation=file://${posixInstallDir} --headless --convert-to ${format}`;`
has to be changed to three trailing slashes
// line 50
let command = `-env:UserInstallation=file:///${posixInstallDir} --headless --convert-to ${format}`;`
I have stumbled across the "file URI scheme" which explains why this is working: https://en.wikipedia.org/wiki/File_URI_scheme
As of Feb 21, running on the same error, a variant of @kennylbj solution worked for me:
index.js L46
// let command = `-env:UserInstallation=file://${installDir.name} --headless --convert-to ${format}`;
command = `--headless --convert-to ${format}`;
1.3.3 does not fix this issue?
This is still an issue on windows 10 with version 1.3.5
Came across the same issue on windows. Installed LibreOffice and checked the file path mentioned in the node module to make it work.
Code looks like:
const libre = require('libreoffice-convert');
libre.convertAsync = require('util').promisify(libre.convert);
const pdfBuf = await libre.convertAsync(doc.getZip().generate({
type: "nodebuffer",
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
}), 'pdf', undefined);
And then I proceeded with using the buffer according to my use case. Thank you for sharing the resources in the above comments, it helped a lot! Cheers!
It works well in OSX but when I deploy it to windows(both in win10 and win7) it failed, and the error is something like:
I do check the bootstrap.ini file and find that content is well defined.
However, I can open soffice.exe and lanch LibreOffice by clicking the file Icon.
LibreOffice version: V7.0 (lastest)