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: {
|
|
|
|
top: "20mm",
|
|
|
|
right: "20mm",
|
|
|
|
bottom: "20mm",
|
|
|
|
left: "20mm"
|
|
|
|
},
|
|
|
|
});
|
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();
|