rework to allow for image gen
All checks were successful
ci/woodpecker/push/ci Pipeline was successful

This commit is contained in:
Madison Grubb
2025-09-04 16:52:13 -04:00
parent af315783e0
commit 1e1d745e55
9 changed files with 372 additions and 135 deletions

30
generatePDF.js Normal file
View File

@@ -0,0 +1,30 @@
import puppeteer from "puppeteer";
import { dungeonTemplate } from "./dungeonTemplate.js";
import fs from 'fs/promises';
export async function generatePDF(data, outputPath = "dungeon.pdf") {
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
// Convert image to base64
const imageBuffer = await fs.readFile(data.map);
const base64Image = `data:image/png;base64,${imageBuffer.toString("base64")}`;
data.map = base64Image;
const html = dungeonTemplate(data);
await page.setContent(html, { waitUntil: "networkidle0" });
await page.pdf({
path: outputPath,
format: "A4",
landscape: true,
printBackground: true,
});
await browser.close();
console.log(`Dungeon PDF saved to ${outputPath}`);
}