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

Download as PDF button



I have a inline visualforce page on an object detail page.


I want to have a Button on the object detail page  which will dowload this page.

Anybody know how to do this?





From the top of my head, you can create a Visualforce page which will with RenderAs=PDF attribute.


You page would be something like this:


<apex:page standardController="Account"  showHeader="true" tabStyle="account" renderas="pdf" >


<apex:detail relatedList="true" title="true"/>




You will then create a button that points to the visualforce page.


If the above didn't work for you, you could always code a boolean from a paramter and throw a If statement in the renderAs flag in the apex:page tag: renderAs="{!IF(printable,'pdf','')}"


and throw a simple commandlink (or button) like: <apex:commandLink value="View PDF" action="{!printPDF}"/>


Apex code:


Public Boolean printable {get; set;}


Public PageController()


printable = ((ApexPages.CurrentPage().getParameters().get('pdf') == 'true')?true:false);



public PageReference printPDF()
PageReference pdf = Page.YourPage;

for (String key : ApexPages.CurrentPage().getParameters().keySet())

//this will preserve your current parameters
pdf.getParameters().put(key, ApexPages.CurrentPage().getParameters().get(key));

return pdf;