I have a html page which contains several html canvas charts. I want to make pdf of this page but without heading ( i.e part of html page which contains multiple canvas elements). I have tried to canvas.toDataURL but it can only write to image. Also this image does not contain original background from html. When I try to do with selector and innerHTML it does not return canvas. Is there way to do this ? This is my testing code.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
headless: false,
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-web-security']
})
const reports = await browser.newPage()
await reports.goto('<myurl>')
await reports.waitFor(5000);
const canvas = await reports.evaluate(() => {
const canvas = document.querySelector("#canvasselector");
// I need to select more broader selector here #largeselector which contains multiple canvas elements and html
return canvas.toDataURL();
});
const base64String = canvas.substr(canvas.indexOf(',') + 1); // get everything after the comma
const imgBuffer = Buffer.from(base64String, 'base64'); //
fs.writeFileSync('test.png', imgBuffer);
await browser.close()
})();