[SalesForce] Print/Download PDF from VF Renderas=PDF in Lightning Experience

I have created a VF page with renderas=PDF and added it as a quick action on the Account object in Lightning Experience. When I click the quick action, a PDF view displays and is correct. How can I add a button or icon to Download that PDF and also a button or icon to Print that PDF?

Best Answer

Print & download option comes from the browser's pdf viewer.

If you still want to have a button somewhere in your org to download the page, have the button, onclick of which redirect the user to the VF page and when the page load, have the following line in the constructor of the controller

Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename=YourFileName.pdf'); 

It should save a PDF in your local drive.

You can have a salesforce button for print as well.

window.print() is the function you need to call from the button, it will send the current page for print.

Please note: you can not have this Javascript in a VF page which is rendered as PDF, JS doesn't run when the page is rendered as PDF.

Related Topic