// most of this is cribbed from https://www.npmjs.com/package/svgs2pdf, but that // tool is CLI-only and wasn't generating PDFs at the right scale import type { Browser } from 'puppeteer'; import Path from 'path'; interface SvgToPdfOptions { browser: Browser; svgs: string[]; outputPath: string; } export async function convertSvgsToPdf({ browser, svgs, outputPath }: SvgToPdfOptions): Promise { const page = await browser.newPage(); const pdfFiles: string[] = []; for (const [index, svg] of svgs.entries()) { const content = ` ${svg} `; await page.setContent(content); const path = Path.join(outputPath, `page-${index + 1}.pdf`); await page.pdf({ format: 'Letter', path }); pdfFiles.push(path); } await page.close(); return pdfFiles; }