libreoffice-convert
libreoffice-convert copied to clipboard
Error to convert Html to Docx
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?
maybe try to use the extension without a dot?
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"
}
hmm strange, does htmlbuffer contain any bytes?
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"
}
Do you have libreoffice installed? At which path?
Am 2. April 2024 17:43:22 MESZ schrieb Vinicius Fernandes @.***>:
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" }
-- Reply to this email directly or view it on GitHub: https://github.com/elwerene/libreoffice-convert/issues/117#issuecomment-2032414627 You are receiving this because you commented.
Message ID: @.***>
Yes, the path is /opt/homebrew/bin/soffice
Then you need to specify the binary path in the config.
Am 2. April 2024 21:58:49 MESZ schrieb Vinicius Fernandes @.***>:
Yes, the path is /opt/homebrew/bin/soffice
-- Reply to this email directly or view it on GitHub: https://github.com/elwerene/libreoffice-convert/issues/117#issuecomment-2032994048 You are receiving this because you commented.
Message ID: @.***>
How I do this?
Change your convert lines to:
const convertAsync = util.promisify(libre.convertWithOptions);
and
const docxBuffer = await convertAsync(htmlBuffer, extension, undefined, {sofficeBinaryPaths: ["/opt/homebrew/bin/soffice"]});
Doesn't worked
@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.
So did you resolve the issue?