elwerene / libreoffice-convert

MIT License
241 stars 94 forks source link

directory not empty, rmdir on windows 10 #28

Closed soubhikchatterjee closed 2 years ago

soubhikchatterjee commented 4 years ago

OS: Windows Server 2019 Node: v14.4.0 npm: 6.14.5

My Code:

const libre = require('libreoffice-convert');

const path = require('path');
const fs = require('fs');

const extend = '.pdf'
const enterPath = path.join(__dirname, '/input/CAD 00001.docx');
const outputPath = path.join(__dirname, `/output/example${extend}`);

// Read file
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) {
      return 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);
});
$ node converter.js
C:\PROJECTS\test\node_modules\rimraf\rimraf.js:310
        throw er
        ^

Error: ENOTEMPTY: directory not empty, rmdir 'C:\Users\VIPUL_~1\AppData\Local\Temp\2\libreofficeConvert_-1312-rs7W0TWfuZDn'
?[90m    at Object.rmdirSync (fs.js:865:3)?[39m
    at rmkidsSync (C:\PROJECTS\test\node_modules\?[4mrimraf?[24m\rimraf.js:349:27)
    at rmdirSync (C:\PROJECTS\test\node_modules\?[4mrimraf?[24m\rimraf.js:329:7)
    at rimrafSync (C:\PROJECTS\test\node_modules\?[4mrimraf?[24m\rimraf.js:301:9)
    at Object._cleanupCallback [as removeCallback] (C:\PROJECTS\test\node_modules\?[4mtmp?[24m\lib\tmp.js:356:16)
    at C:\PROJECTS\test\node_modules\?[4mlibreoffice-convert?[24m\index.js:59:17
    at C:\PROJECTS\test\node_modules\?[4masync?[24m\dist\async.js:473:16
    at C:\PROJECTS\test\node_modules\?[4masync?[24m\dist\async.js:1622:17
    at C:\PROJECTS\test\node_modules\?[4masync?[24m\dist\async.js:969:16
    at C:\PROJECTS\test\node_modules\?[4mlibreoffice-convert?[24m\index.js:35:32 {
  errno: ?[33m-4051?[39m,
  syscall: ?[32m'rmdir'?[39m,
  code: ?[32m'ENOTEMPTY'?[39m,
  path: ?[32m'C:\\Users\\VIPUL_~1\\AppData\\Local\\Temp\\2\\libreofficeConvert_-1312-rs7W0TWfuZDn'?[39m
}

However the above code works fine on macos.

danielpngr commented 4 years ago

Unfortunately I got the same error

elwerene commented 4 years ago

@soubhikchatterjee @randomcrafterHD What version of rimraf do you have installed? It seams like a bug in rimraf on Windows.

danielpngr commented 4 years ago

Previously i think 2.6 but after that didn't work i switched to 3.0.2 with the same result

danielpngr commented 3 years ago

Okay just for those who have the same issue... it's a little bit embarrassing, but in my case the libreoffice installation was broke... reinstalling fixed the issue :)

josejaner commented 3 years ago

continue with the same problem, I already installed it again

danielpngr commented 3 years ago

okay strange... you could also try to perform the command without the library ... then there should be no error concerning the deletion, but you have to take care about the location etc. yourself

In my case i wanted to convert word to pdf on windows start /wait soffice --headless --convert-to pdf "{WORD_INPUT_FILE}" --outdir "{PDF_OUTPUT_FOLDER}" the "start /wait" part is windows specific...

horsul commented 3 years ago

I have the same problem

elwerene commented 3 years ago

I don't have Windows. @all please write a fix MR, I will review and accept it!

Am 8. Juli 2020 14:41:26 MESZ schrieb horsul notifications@github.com:

I have the same problem

mpscheidt commented 3 years ago

Workaround that works for me: Run nodejs server on Windows subsystem for Linux (WSL 2, https://docs.microsoft.com/en-us/windows/wsl/wsl2-index)

whl1295a commented 3 years ago

我测试后的方法,是将libreoffice软件安装到c盘的C:\Program Files\LibreOffice\program目录下面即可

ShaMan123 commented 3 years ago

+1

soyglorialopez commented 3 years ago

As of today, I also have the same problem. I want to convert word to pdf

BahodiRajabov commented 3 years ago

+

elwerene commented 3 years ago

@bdevpro It doesn't help to push on this issue. As I wrote on the 8th of july, I don't have Windows and I don't plan to install it. Please search and fix this bug yourself and post a MR, I will review and merge and upload new versions.

BahodiRajabov commented 3 years ago

@bdevpro It doesn't help to push on this issue. As I wrote on the 8th of july, I don't have Windows and I don't plan to install it. Please search and fix this bug yourself and post a MR, I will review and merge and upload new versions.

Thank you ) I will try to solve it

JCLimpide commented 3 years ago

If it can help anyone, I stumbled into the same issue because libreoffice wasn't installed on the computer. After libreoffice was installed, I run into the other issue #32, but with the fix mentioned there, it finally works now

elwerene commented 3 years ago

Please try https://github.com/elwerene/libreoffice-convert/pull/51

ghostvar commented 3 years ago

I am use windows and also have same experience about this error,

like what @JCLimpide said, so make sure you have install libreoffice on your system.

also for @elwerene I have suggestion to make config/options for custom installation path because I installed libreoffice in D drive. I will make pull request if have free time.

thanks.

elwerene commented 3 years ago

@ghostvar make a pull request and I will review and release it :)

thiagodevvv commented 2 years ago

Hi everybody, I ran into the same error... I had not read the requirements "Please install libreoffice in /Applications (Mac), with your favorite package manager (Linux), or with the msi (Windows)". Download and install works for me: https://www.libreoffice.org/donate/dl/win-x86_64/7.2.0/pt/LibreOffice_7.2.0_Win_x64.msi

Bye

WafiqSalie commented 1 year ago

OS: Windows Server 2019 Node: v14.4.0 npm: 6.14.5

My Code:

const libre = require('libreoffice-convert');

const path = require('path');
const fs = require('fs');

const extend = '.pdf'
const enterPath = path.join(__dirname, '/input/CAD 00001.docx');
const outputPath = path.join(__dirname, `/output/example${extend}`);

// Read file
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) {
      return 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);
});
$ node converter.js
C:\PROJECTS\test\node_modules\rimraf\rimraf.js:310
        throw er
        ^

Error: ENOTEMPTY: directory not empty, rmdir 'C:\Users\VIPUL_~1\AppData\Local\Temp\2\libreofficeConvert_-1312-rs7W0TWfuZDn'
?[90m    at Object.rmdirSync (fs.js:865:3)?[39m
    at rmkidsSync (C:\PROJECTS\test\node_modules\?[4mrimraf?[24m\rimraf.js:349:27)
    at rmdirSync (C:\PROJECTS\test\node_modules\?[4mrimraf?[24m\rimraf.js:329:7)
    at rimrafSync (C:\PROJECTS\test\node_modules\?[4mrimraf?[24m\rimraf.js:301:9)
    at Object._cleanupCallback [as removeCallback] (C:\PROJECTS\test\node_modules\?[4mtmp?[24m\lib\tmp.js:356:16)
    at C:\PROJECTS\test\node_modules\?[4mlibreoffice-convert?[24m\index.js:59:17
    at C:\PROJECTS\test\node_modules\?[4masync?[24m\dist\async.js:473:16
    at C:\PROJECTS\test\node_modules\?[4masync?[24m\dist\async.js:1622:17
    at C:\PROJECTS\test\node_modules\?[4masync?[24m\dist\async.js:969:16
    at C:\PROJECTS\test\node_modules\?[4mlibreoffice-convert?[24m\index.js:35:32 {
  errno: ?[33m-4051?[39m,
  syscall: ?[32m'rmdir'?[39m,
  code: ?[32m'ENOTEMPTY'?[39m,
  path: ?[32m'C:\\Users\\VIPUL_~1\\AppData\\Local\\Temp\\2\\libreofficeConvert_-1312-rs7W0TWfuZDn'?[39m
}

However the above code works fine on macos.

I got the similar error on windows. after struggling for hours the solution is simple. In libreOffice>index.js line #17 to #71, make sure the paths is correct. In my case I had to add 'programfiles' instead of 'programfiles(86)'. Depending on the windows version your path will vary. I hope this helps anyone

BahodiRajabov commented 1 year ago

Thank you

On Mon, Aug 22, 2022, 11:35 AM WafiqSalie @.***> wrote:

OS: Windows Server 2019 Node: v14.4.0 npm: 6.14.5

My Code:

const libre = require('libreoffice-convert');

const path = require('path'); const fs = require('fs');

const extend = '.pdf' const enterPath = path.join(dirname, '/input/CAD 00001.docx'); const outputPath = path.join(dirname, /output/example${extend});

// Read file 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) { return 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);

});

$ node converter.js C:\PROJECTS\test\node_modules\rimraf\rimraf.js:310 throw er ^

Error: ENOTEMPTY: directory not empty, rmdir 'C:\Users\VIPUL~1\AppData\Local\Temp\2\libreofficeConvert-1312-rs7W0TWfuZDn' ?[90m at Object.rmdirSync (fs.js:865:3)?as removeCallback at rmdirSync (C:\PROJECTS\test\node_modules\?[4mrimraf?[24m\rimraf.js:329:7) at rimrafSync (C:\PROJECTS\test\node_modules\?[4mrimraf?[24m\rimraf.js:301:9) at Object._cleanupCallback [as removeCallback] (C:\PROJECTS\test\node_modules\?[4mtmp?[24m\lib\tmp.js:356:16) at C:\PROJECTS\test\node_modules\?[4mlibreoffice-convert?[24m\index.js:59:17 at C:\PROJECTS\test\node_modules\?[4masync?[24m\dist\async.js:473:16 at C:\PROJECTS\test\node_modules\?[4masync?[24m\dist\async.js:1622:17 at C:\PROJECTS\test\node_modules\?[4masync?[24m\dist\async.js:969:16 at C:\PROJECTS\test\nodemodules\?[4mlibreoffice-convert?[24m\index.js:35:32 { errno: ?[33m-4051?[39m, syscall: ?[32m'rmdir'?[39m, code: ?[32m'ENOTEMPTY'?[39m, path: ?[32m'C:\Users\VIPUL~1\AppData\Local\Temp\2\libreofficeConvert_-1312-rs7W0TWfuZDn'?[39m }

However the above code works fine on macos.

I got the similar error on windows. after struggling for hours the solution is simple. In libreOffice>index.js line #17 https://github.com/elwerene/libreoffice-convert/issues/17 to #71 https://github.com/elwerene/libreoffice-convert/issues/71, make sure the paths is correct. In my case I had to add 'programfiles' instead of 'programfiles(86)'. Depending on the windows version your path will vary. I hope this helps anyone

— Reply to this email directly, view it on GitHub https://github.com/elwerene/libreoffice-convert/issues/28#issuecomment-1221909746, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQM7YQ2APBSMC64UM2EWFBTV2MNRHANCNFSM4N7OSYMA . You are receiving this because you were mentioned.Message ID: @.***>

mihir254 commented 8 months ago

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!