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:


<apex:page renderAs=”pdf”>


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.



Visualforce Page as pdf

View More:


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.

Thank You.