add pdflatex

This commit is contained in:
C4illin 2024-05-29 11:59:52 +02:00
parent 284caa592f
commit 3872cd87b6
3 changed files with 57 additions and 0 deletions

View file

@ -15,6 +15,11 @@ import {
properties as propertiesGraphicsmagick,
} from "./graphicsmagick";
import {
convert as convertPdflatex,
properties as propertiesPdflatex,
} from "./pdflatex";
import { normalizeFiletype } from "../helpers/normalizeFiletype";
// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
@ -49,6 +54,10 @@ const properties: {
properties: propertiesImage,
converter: convertImage,
},
pdflatex: {
properties: propertiesPdflatex,
converter: convertPdflatex,
},
pandoc: {
properties: propertiesPandoc,
converter: convertPandoc,

View file

@ -0,0 +1,42 @@
import { exec } from "node:child_process";
export const properties = {
from: {
text: ["tex", "latex"],
},
to: {
text: ["pdf"],
},
};
export function convert(
filePath: string,
fileType: string,
convertTo: string,
targetPath: string,
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
options?: any,
): Promise<string> {
return new Promise((resolve, reject) => {
// const fileName: string = (targetPath.split("/").pop() as string).replace(".pdf", "")
const outputPath = targetPath.split("/").slice(0, -1).join("/").replace("./", "")
exec(
`pdflatex -interaction=nonstopmode -output-directory="${outputPath}" "${filePath}"`,
(error, stdout, stderr) => {
if (error) {
reject(`error: ${error}`);
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stderr) {
console.error(`stderr: ${stderr}`);
}
resolve("success");
},
);
});
}