rework to allow for image gen
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
This commit is contained in:
30
generatePDF.js
Normal file
30
generatePDF.js
Normal 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}`);
|
||||
}
|
||||
Reference in New Issue
Block a user