How can I convert .pdf to .docx file with libreoffice-convert using nodejs?

Viewed 32

I want to convert .pdf to .docx file with libreoffice-convert using nodejs and libreoffice-convert. This is an example code from this package. How can I use this example?

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

const libre = require('libreoffice-convert');
libre.convertAsync = require('util').promisify(libre.convert);

async function main() {
    const ext = '.docx'
    const inputPath = path.join(__dirname, '/resources/example.pdf');
    const outputPath = path.join(__dirname, `/resources/example${ext}`);
    const file = await fs.readFile(inputPath);
    let conv = await libre.convertAsync(file, ext, undefined);
    await fs.writeFile(outputPath, conv);
}

main().catch(function (err) {
    console.log(`Error converting file: ${err}`);
});
0 Answers
Related