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

Error to convert Html to Docx #117

Open
ViniCleFer opened this issue Apr 1, 2024 · 12 comments
Open

Error to convert Html to Docx #117

ViniCleFer opened this issue Apr 1, 2024 · 12 comments

Comments

@ViniCleFer
Copy link

I'm executing this code:

const convertAsync = util.promisify(libre.convert);

export async function convertHTMLToWord(file: string) {
  try {
    const extension = '.docx';

    const inputPath = `${__dirname}/example.html`;
    const outputPath = `${__dirname}/example${extension}`;

    await fs.writeFile(inputPath, file);

    const htmlBuffer = await fs.readFile(inputPath);

    const docxBuffer = await convertAsync(htmlBuffer, extension, undefined);

    await fs.writeFile(outputPath, docxBuffer);

    const base64StringWord = await fs.readFile(outputPath, 'base64');

    const mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';

    const dataBase64 = `data:${mimetype};base64,${base64StringWord}`;

    return dataBase64;
  } catch (e) {
    console.error('Error convertHTMLToWord', JSON.stringify(e, null, 2));
  }
}

And I received this:

Error convertHTMLToWord {
  "errno": -2,
  "code": "ENOENT",
  "syscall": "open",
  "path": "/var/folders/q0/kspr59sd4zs2l0qw7ss2qzdh0000gn/T/libreofficeConvert_-63259-vGZ5lZsbRSqP/source..docx"
}

Ca you help me, please?

@elwerene
Copy link
Owner

elwerene commented Apr 2, 2024

maybe try to use the extension without a dot?

@ViniCleFer
Copy link
Author

ViniCleFer commented Apr 2, 2024

On code of exeplain how to use there is a dot, but I followed your suggestion and remove the dot now and I received the same error.

Error convertHTMLToWord {
  "errno": -2,
  "code": "ENOENT",
  "syscall": "open",
  "path": "/var/folders/q0/kspr59sd4zs2l0qw7ss2qzdh0000gn/T/libreofficeConvert_-72754-J4uShWs5Ba9O/source.docx"
}

@elwerene
Copy link
Owner

elwerene commented Apr 2, 2024

hmm strange, does htmlbuffer contain any bytes?

@ViniCleFer
Copy link
Author

Yes

htmlBuffer <Buffer 3c 70 20 73 74 79 6c 65 3d 22 74 65 78 74 2d 61 6c 69 67 6e 3a 20 6a 75 73 74 69 66 79 3b 20 6c 69 6e 65 2d 68 65 69 67 68 74 3a 20 31 2e 35 3b 22 3e ... 65 more bytes>

Error convertHTMLToWord {
  "errno": -2,
  "code": "ENOENT",
  "syscall": "open",
  "path": "/var/folders/q0/kspr59sd4zs2l0qw7ss2qzdh0000gn/T/libreofficeConvert_-89990-URymgrEgBS1s/source.docx"
}

@elwerene
Copy link
Owner

elwerene commented Apr 2, 2024 via email

@ViniCleFer
Copy link
Author

Yes, the path is /opt/homebrew/bin/soffice

@elwerene
Copy link
Owner

elwerene commented Apr 2, 2024 via email

@ViniCleFer
Copy link
Author

How I do this?

@elwerene
Copy link
Owner

elwerene commented Apr 2, 2024 via email

@ViniCleFer
Copy link
Author

Doesn't worked

@elwerene
Copy link
Owner

elwerene commented Apr 8, 2024

@ViniCleFer can you set a breakpoint in the convert task? it seems it can not write into your temporary directory. Maybe you can check at the open call if the folder exists. You could set a breakpoint in line 16 of index.js.

@elwerene
Copy link
Owner

elwerene commented Jun 6, 2024

So did you resolve the issue?

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

No branches or pull requests

2 participants