Hi readers, Here we will see how can we render a Visualforce Page as PDF. The renderAs attribute is used for the same purpose.
Render a Visualforce Page as PDF:
To render a Visualforce Page as PDF we need to add renderAs=”pdf” attribute in <apex:page> component. Here is the Syntax:
The example that I am going to create will display Account details Like Account Name, Account Number, Billing State, Billing City etc along with related Contact List, Opportunity List and Case List as PDF in the browser. Visualforce pages rendered as PDFs will either display in the browser or download as a PDF file, depending on your browser settings.
Now, Login to your Salesforce Account and Open Developer Console.
Create an Apex class:
Create a Class called AccountDetailsHandler.
Create a Visualforce Page:
Create a Visualforce Page called PrintAccountDetails and write the following code.
Test Visualforce Page:
You need to replace yoursalesforceinstance with you Salesforce Instance and Id with your org Account ID.
- Upload Attachment to a Record using Visualforce Page in Salesforce.
- aura:unescapedHtml In Lightning Component Salesforce.
- What is Trigger Factory in Salesforce?
- Create a Quick Action in Lightning Experience Salesforce
I hope this is a useful post for you. Please don’t hesitate to comment for any technical issues. Your feedback and suggestions are important to me.