This commit is contained in:
Jason Fu 2025-06-26 04:01:47 +02:00
parent bd36314f00
commit dcb15aee0e
3 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,45 @@
import { execFile } from "node:child_process";
export const properties = {
from: {
text: ["docx", "txt"],
},
to: {
text: ["pdf", "txt"],
},
};
export function convert(
filePath: string,
fileType: string,
convertTo: string,
targetPath: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options?: unknown,
): Promise<string> {
const outputPath = targetPath.split("/").slice(0, -1).join("/").replace("./", "");
// Build arguments array
const args: string[] = [];
args.push("--headless");
args.push("--convert-to", convertTo, filePath);
args.push("--outdir", outputPath);
return new Promise((resolve, reject) => {
execFile("soffice", args, (error, stdout, stderr) => {
if (error) {
reject(`error: ${error}`);
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stderr) {
console.error(`stderr: ${stderr}`);
}
resolve("Done");
});
});
}