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() {
|
|
|
|
const htmlPdf = new PuppeteerHTMLPDF();
|
2024-08-12 08:17:41 +00:00
|
|
|
|
2024-08-12 08:25:57 +00:00
|
|
|
htmlPdf.setOptions({
|
2024-08-12 08:17:41 +00:00
|
|
|
format: "A4",
|
2024-08-12 08:25:57 +00:00
|
|
|
});
|
2024-08-12 08:17:41 +00:00
|
|
|
|
2024-08-12 08:25:57 +00:00
|
|
|
try {
|
|
|
|
const html = await htmlPdf.readFile(`${__dirname}/../dist/all.html`, "utf8");
|
2024-08-12 08:17:41 +00:00
|
|
|
|
|
|
|
const pdfBuffer = await htmlPdf.create(html);
|
2024-08-12 08:25:57 +00:00
|
|
|
const path = `${__dirname}/../dist/result.pdf`;
|
2024-08-12 08:17:41 +00:00
|
|
|
await htmlPdf.writeFile(pdfBuffer, path);
|
2024-08-12 08:25:57 +00:00
|
|
|
|
2024-08-12 08:17:41 +00:00
|
|
|
console.log("PDF created successfully");
|
2024-08-12 08:25:57 +00:00
|
|
|
} catch (error) {
|
2024-08-12 08:17:41 +00:00
|
|
|
console.error("Error creating PDF", error);
|
2024-08-12 08:25:57 +00:00
|
|
|
}
|
2024-08-12 08:17:41 +00:00
|
|
|
}
|
2024-08-12 08:25:57 +00:00
|
|
|
|
|
|
|
generatePDF();
|