Use server-side code for downloading PDFs. It's a lot easier.
With JavaScript, you often need to trick the Print API, to open the document, hide the display, and then download etc. It's not worth it. And since the source of the file is usually stored on the server, it makes sense to download it server-side.
Not sure if it fits your setup, but alfareport.com does CLI-based PDF generation from JS scripts. Supports tables, images, and even digital signatures if you need that.