function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Eric BissonnetteEric Bissonnette 

Generate pdf from Visualforce and assign it to a action button

Trying to get a better output of my account tab than the "Printable View"
I would like to Generate pdf from Visualforce and assign it to a action button.  This way by one simple click they will have a client snapshot.
Thanks
Eric
 
Best Answer chosen by Eric Bissonnette
AbhishekAbhishek (Salesforce Developers) 
You can able to export any page as PDF using renderas attribute in visualforce page tag

<apex:page renderAs="pdf">
Create one more visualforce page with same controller code and visualforce page code and the only change is use renderas attribute in the visualforce page code. Then call this visualforce page from the 'Export to PDF' custom button action and pass the necessary parameters to the visualforce page to render the data as PDF page. 

Check this visual force developer guide for more details - https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_renderas_pdf.htm


For further reference, You can use the below code,
http://www.interactiveties.com/blog/2015/visualforce-button-pdf.php


If it helps mark this as the best answer.

All Answers

AbhishekAbhishek (Salesforce Developers) 
You can able to export any page as PDF using renderas attribute in visualforce page tag

<apex:page renderAs="pdf">
Create one more visualforce page with same controller code and visualforce page code and the only change is use renderas attribute in the visualforce page code. Then call this visualforce page from the 'Export to PDF' custom button action and pass the necessary parameters to the visualforce page to render the data as PDF page. 

Check this visual force developer guide for more details - https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_renderas_pdf.htm


For further reference, You can use the below code,
http://www.interactiveties.com/blog/2015/visualforce-button-pdf.php


If it helps mark this as the best answer.
This was selected as the best answer
Gabriel LinusGabriel Linus
Hi Eric,

Here are the steps to generate a PDF from a Visualforce page and assign it to an action button:
  1. Create a Visualforce page and controller that contain the content you want to include in the PDF.
  2. Add the "renderAs" attribute to the apex:page tag, setting it to "pdf", to ensure that the page is rendered as a PDF:
  3. Create a button or link that, upon clicking, will render a Visualforce page as a PDF by assigning the Visualforce page to it.
To learn more about generating PDFs in Salesforce, you can refer to the article at https://arrify.com/generate-pdf-in-salesforce/. This article provides a detailed guide with step-by-step demonstrations on PDF generation in Salesforce, covering various methods and limitations.