I am trying to generate PDF using Puppeteer, but input fields and checkboxes are not editable. Is it possible to make them editable, and if so, how?
// ...
const _conf = _.merge(conf, {
format: 'A4',
margin: {
left: '15px',
top: '15px',
right: '15px',
bottom: '15px'
}
});
const browser = await puppeteer.launch({ headless: true })
const page = await browser.newPage()
await page.setContent(html)
const buffer = await page.pdf()
await browser.close()
return buffer;
Yes, it is possible to make input fields and checkboxes editable in Puppeteer. You can use the page.evaluate()
method to execute a script in the context of the page to set the readOnly
attribute to false
for all input fields and checkboxes. Here’s an example:
const browser = await puppeteer.launch({ headless: true })
const page = await browser.newPage()
await page.setContent(html)
await page.evaluate(() => {
const inputs = document.querySelectorAll('input')
inputs.forEach(input => {
input.readOnly = false
})
const checkboxes = document.querySelectorAll('input[type="checkbox"]')
checkboxes.forEach(checkbox => {
checkbox.disabled = false
})
})
const buffer = await page.pdf()
await browser.close()
return buffer;
This code will set the readOnly
attribute to false
for all input fields and the disabled
attribute to false
for all checkboxes, making them editable in the generated PDF.