md2pdf-meow/scripts/convert.ts

30 lines
723 B
TypeScript
Raw Permalink Normal View History

2024-08-12 08:25:57 +00:00
import PuppeteerHTMLPDF from 'puppeteer-html-pdf';
2024-08-12 08:17:41 +00:00
2024-08-12 08:25:57 +00:00
async function generatePDF() {
2024-08-12 11:59:23 +00:00
const htmlPdf = new PuppeteerHTMLPDF();
2024-08-12 08:17:41 +00:00
2024-08-12 11:59:23 +00:00
htmlPdf.setOptions({
format: "A4",
margin: {
2024-08-12 12:04:06 +00:00
top: "16mm",
right: "16mm",
bottom: "16mm",
left: "16mm"
2024-08-12 11:59:23 +00:00
},
});
2024-08-12 08:17:41 +00:00
2024-08-12 11:59:23 +00:00
try {
const html = await htmlPdf.readFile(`${__dirname}/../dist/all.html`, "utf8");
2024-08-12 08:17:41 +00:00
2024-08-12 11:59:23 +00:00
const pdfBuffer = await htmlPdf.create(html);
const path = `${__dirname}/../dist/result.pdf`;
await htmlPdf.writeFile(pdfBuffer, path);
console.log("PDF created successfully");
} catch (error) {
console.error("Error creating PDF", error);
}
2024-08-12 08:17:41 +00:00
}
2024-08-12 08:25:57 +00:00
generatePDF();