Using:
var doc = new PDFDocument();
doc.pipe(res);
doc.text('Add content here');
doc.end();
within an Express GET
route I'm able to navigate in the browser and view the PDF. Once viewed it can be saved or printed.
That's good, but what I need is for the PDF to automatically download. The application will send a PUT
to Express. From the one PUT
, is it possible to also auto-download the PDF? Angular needs a 200 response to return control to Angular and the user, but the PDF also needs to be downloaded.
I've tried res.end(new Buffer(doc), 'binary)
, res.send(new Buffer(doc, 'binary'))
, etc, but can't get the PDF to download. If I can't return a 200 and download the PDF from a PUT
then my fallback is to PUT
and once that returns do a window.open
to the GET
route to view the PDF. Kind of hacky, so I would really prefer a download.
Options?