Node Puppeteer generating PDF not including Form Inputs

1.2k views Asked by At

I'm trying to use Puppeteer ( https://github.com/GoogleChrome/puppeteer) to create a PDF file for an express app, here is the code:

var puppeteer = require('puppeteer');

var browser = await puppeteer.launch({headless: true});
var page = await browser.newPage();
await page.goto(fullUrl + '/#shareDiv', {waitUntil: 'networkidle'});
page.emulateMedia('screen');
await page.pdf({path:'./uploads/pdfDownload'+Date.now()+'.pdf', printBackground: true, width: '1000px'});

browser.close();

That generates a pretty good PDF but it is hiding any input elements (radios, checkboxes, etc.)

Also I want to target a specific div referenced by ID.

One other thing is get rid of pages on the PDF.

Is this type of customization available on Puppeteer?

2

There are 2 answers

0
browserless On

Puppeteer will use print-media to generate the PDF, so you'll probably want to try and emulate a screen and see if that fixes your issues (see docs here).

0
Jordash On

If anyone runs into an problem similar to this, note that Pupeteer pretty much matches Chrome exactly, so if you are using Mozilla Firefox to test it wont match your PDF exactly, so test in Chrome when using Puppeteer and will be much smoother.