From 5ba02f1054e8fc72baa99faac4f38f231251acb4 Mon Sep 17 00:00:00 2001 From: rca Date: Mon, 12 Aug 2024 20:59:23 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=9E=E3=83=BC=E3=82=B8=E3=83=B3=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/convert.ts | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/scripts/convert.ts b/scripts/convert.ts index f7625be..a1afb2f 100644 --- a/scripts/convert.ts +++ b/scripts/convert.ts @@ -1,23 +1,29 @@ import PuppeteerHTMLPDF from 'puppeteer-html-pdf'; async function generatePDF() { - const htmlPdf = new PuppeteerHTMLPDF(); + const htmlPdf = new PuppeteerHTMLPDF(); - htmlPdf.setOptions({ - format: "A4", - }); + htmlPdf.setOptions({ + format: "A4", + margin: { + top: "20mm", + right: "20mm", + bottom: "20mm", + left: "20mm" + }, + }); - try { - const html = await htmlPdf.readFile(`${__dirname}/../dist/all.html`, "utf8"); + try { + const html = await htmlPdf.readFile(`${__dirname}/../dist/all.html`, "utf8"); - 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); - } + 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); + } } generatePDF();