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
Kavya M 43Kavya M 43 

Hellooooooooo

I want to develop a button in my page. Let's say that button name is "Print". When you click on that "Print" button it should print the page in a PPT / PDF format. 

I want your inputs to get an idea about this. I really don't know where to start and how to start. Can you guys help me?
Khan AnasKhan Anas (Salesforce Developers) 
Hi Kavya,

Greetings to you!

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page renderAs="{!render}" id="rer" controller="PrintPdfVfC" >
    <apex:form>
        <apex:pageBlock>
            Set output that you want in PDF
        </apex:pageBlock> 
        <apex:commandButton value="Convert To PDF" action="{!pdfpage}" />
    </apex:form>
</apex:page>

Controller:
public class PrintPdfVfC {
    
    public boolean pdfpage {set;get;}
    public string render{set;get;}
    
    public void pdfpage(){
        if(render==null){
            render='pdf';
        }
    }
}

If you want to render the page in PDF from different visualforce page button, you can use the below code.

Visualforce 1:
<apex:page renderAs="pdf" >
    <apex:form>
        <apex:pageBlock>
            Set output that you want in PDF
        </apex:pageBlock>
    </apex:form>     
</apex:page>

Visualforce 2:
<apex:page >
    <apex:form>
        <apex:pageBlock>
            <apex:commandButton value="Convert To PDF" action="/apex/page1" />
        </apex:pageBlock>
    </apex:form>     
</apex:page>

If you want to format a visualforce page rendered as PDF, you can refer to below knowledge article.

https://help.salesforce.com/articleView?id=000004706&language=en_US&type=1

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas