I need to create a PDF like this.
A bit more information about current function where I am trying to capture these images:
const createImages = async (orderSpecifications, logger) => {
let browser, page;
try {
// Initialize Puppeteer browser and page
browser = await puppeteer.launch({
headless: true, // Set to false if you want to see the browser UI
executablePath: "/usr/bin/chromium",
arg: [
"--no-sandbox",
"--headless",
"--swiftshader-webgl",
"--use-gl=swiftshader",
],
});
page = await browser.newPage();
// Setup a promise to wait for a specific console message
const waitForConsoleMessage = new Promise((resolve) => {
page.on("console", (msg) => {
if (msg.text().includes("PlayCanvas App Started!")) {
// Adjust the message text as needed
logger.info("Detected PlayCanvas load completion in console.");
resolve();
}
});
});
// Navigate to the page
// await page.goto("https://playcanv.as/p/93709109/", { waitUntil: 'networkidle0' });
await page.goto("https://get.webgl.org/", { waitUntil: "networkidle0" });
// Wait for the specific console message
// await waitForConsoleMessage;
// await new Promise(resolve => setTimeout(resolve, 10000));
// Send SKU details and configurations to PlayCanvas
for (const spec of orderSpecifications) {
const details = {
type: "SKU_details",
sku: spec.sku,
};
if (spec.properties) {
if (spec.properties.font) {
details.font = spec.properties.font;
}
if (spec.properties.engravingText) {
details.engravingText = spec.properties.engravingText;
}
if (spec.properties.printImage) {
details.printImage = spec.properties.printImage;
}
}
// Send the details to PlayCanvas
await page.evaluate((details) => {
window.postMessage(details, "*");
}, details);
}
const screenshots = [];
// Define camera angles and take screenshots from specified angles
const cameraAngles = [7, 5, 8]; // Example camera angles: Front, Side, and Back
for (let index of cameraAngles) {
await page.evaluate((index) => {
window.postMessage({ type: "CameraChange", index }, "*");
}, index);
// Wait a moment for the camera to settle
await new Promise((resolve) => setTimeout(resolve, 1000));
// Take a screenshot and store it
const buffer = await page.screenshot();
screenshots.push(buffer.toString("base64"));
}
// Close the browser once done
await browser.close();
// Return or handle the screenshots as needed
return screenshots;
} catch (error) {
console.error("Error during image generation:", error);
await browser.close();
throw error; // Rethrow or handle error as needed
}
};