Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download PDF file using PUPPETEER after form submit? NodeJS | PUPPETEER

I've been trying to download a PDF file using headless chrome. What I got to do is send a form with some info, on form submit it should download a PDF. How do I save this PDF? Obs: I'm using NodeJS as the framework.

like image 453
Vinicius Martins Avatar asked Sep 20 '18 15:09

Vinicius Martins


People also ask

How does puppeteer PDF work?

The documentation says: Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium. It's basically a browser which you can run from Node.


1 Answers

I do not know exactly how the pdf is downloaded but I think you can use the following.

await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: '/home/me/stuff'});

And then check for the file to be in the directory specified in the downloadPath property.

like image 160
usuario Avatar answered Sep 27 '22 18:09

usuario