convert pdf to office
how can I solve pdf to office or pdf to word. using node js or use node js library.
exports.convertToDoc = catchAsyncError(async (req, res, next) => {
const filePath = req.file.path;
const fileName = req.file.originalname;
const outputDir = path.join(__dirname, "..", "public/uploads");
con
try {
const outputFilePath = path.join(outputDir, outputFileName);
const command = `unoconv -f docx -o ${outputDir} ${filePath}`;
exec(command, async (error) => {
if (error) {
console.error(`Error occurred during the conversion process: ${error}`);
return next(
new ErrorHandler(
"Error occurred during the conversion process.",
500,
),
);
}
res.download(outputFilePath, (err) => {
if (err) {
console.error(`Error occurred during the download process: ${err}`);
next(
new ErrorHandler(
"Error occurred during the download process.",
404,
),
);
}
fs.unlinkSync(filePath);
fs.unlinkSync(outputFilePath);
});
});
} catch (err) {
console.error(`Error occurred during the conversion process: ${err}`);
fs.unlinkSync(filePath);
next(
new ErrorHandler("Error occurred during the conversion process.", 500),
);
}
Error
"Error occurred during the conversion process."
and what is the reason for this problem.