Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work in windows #32

Closed
kennylbj opened this issue Aug 14, 2020 · 11 comments
Closed

Doesn't work in windows #32

kennylbj opened this issue Aug 14, 2020 · 11 comments

Comments

@kennylbj
Copy link

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:

The program can't start because the config file [C:\Program Files\LibreOffice\program\bootstrap.ini] has corrupted.

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)

@elwerene
Copy link
Owner

elwerene commented Aug 14, 2020 via email

@kennylbj
Copy link
Author

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?

@elwerene
Copy link
Owner

@kennylbj #27

@ilkohoffmann
Copy link

ilkohoffmann commented Nov 10, 2020

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

@ilkohoffmann
Copy link

From Pull-request #47 (comment)

@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 with path.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}`;`

@ilkohoffmann
Copy link

I have stumbled across the "file URI scheme" which explains why this is working: https://en.wikipedia.org/wiki/File_URI_scheme

@JCLimpide
Copy link

JCLimpide commented Feb 25, 2021

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

@elwerene
Copy link
Owner

Please try #51

@ivysrono
Copy link

1.3.3 does not fix this issue?

@avimar
Copy link

avimar commented Feb 2, 2022

This is still an issue on windows 10 with version 1.3.5

elwerene added a commit that referenced this issue Mar 29, 2022
Converting paths to a file, fixing #32
@mihir254
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants