setup
This commit is contained in:
parent
bd36314f00
commit
dcb15aee0e
3 changed files with 60 additions and 0 deletions
45
src/converters/libreoffice.ts
Normal file
45
src/converters/libreoffice.ts
Normal 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");
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue