mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-08 01:46:28 +01:00
24 lines
592 B
TypeScript
24 lines
592 B
TypeScript
import latex from 'node-latex';
|
|
import { Readable } from 'stream';
|
|
|
|
const latexToPdf = (doc: string) =>
|
|
new Promise<Buffer>((resolve, reject) => {
|
|
const chunks: Buffer[] = [];
|
|
const input = new Readable();
|
|
input.push(doc);
|
|
input.push(null);
|
|
const latexStream = latex(input);
|
|
latexStream.on('data', (chunk) => {
|
|
chunks.push(Buffer.from(chunk));
|
|
});
|
|
latexStream.on('finish', () => {
|
|
const result = Buffer.concat(chunks);
|
|
resolve(result);
|
|
});
|
|
latexStream.on('error', (err) => {
|
|
reject(err);
|
|
});
|
|
});
|
|
|
|
export { latexToPdf };
|