Generating PDF with Puppeteer Excluding Form Fields

I’m attempting to utilize Puppeteer to generate a PDF for an Express application. Below is my current implementation:

const puppeteer = require('puppeteer');

const browserInstance = await puppeteer.launch({headless: true});
const newPage = await browserInstance.newPage();
await newPage.goto(fullUrl + '/#shareSection', {waitUntil: 'networkidle'});
newPage.emulateMedia('screen');
await newPage.pdf({path: './uploads/myPDF' + Date.now() + '.pdf', printBackground: true, width: '1000px'});

browserInstance.close();

This code produces a satisfactory PDF, but unfortunately, it does not include form elements such as radio buttons and checkboxes. Additionally, I need to focus on a specific div by its ID and eliminate any page breaks in the PDF. Is it possible to achieve these customizations using Puppeteer?

Hey! You can use Puppeteer’s page.evaluate() to manipulate the DOM before generating the PDF. To remove a specific div, set its display to ‘none’. For printing form elements, try injecting custom CSS to style them. There might be a bit of trial and error involved, but it’s doable!