Rendering PDF Files Using Visualforce Page

Rendering PDF files using a Visualforce page in Salesforce is a common requirement, especially when you need to generate printable documents such as reports, invoices, or statements. Salesforce provides a way to generate PDF files directly from Visualforce pages using the renderAs attribute. 

 

Visualforce

<apex:page controller="PDFRenderingController" renderAs="pdf">

  <apex:form >

    <apex:pageBlock >

        <apex:pageBlockTable value="{!accList}" var="acc" border="2">

           <apex:column value="{!acc.Name}"/>

           <apex:column value="{!acc.AnnualRevenue}"/>

           <apex:column value="{!acc.Type}"/>

           <apex:column value="{!acc.AccountNumber}"/>

           <apex:column value="{!acc.Rating}"/>

        </apex:pageBlockTable>

    </apex:pageBlock>

  </apex:form>

</apex:page>

Controller

public with sharing class PDFRenderingController {

    public List accList{get;set;}

    public PDFRenderingController (){

        accList = [select Id,Name,type,AccountNumber,AnnualRevenue,Rating from Account limit 10];

    }

}

Format a Visualforce page rendered as PDF

Best Practices for Rendering PDF Files



Comments

Popular posts from this blog

Introduction to Salesforce Agent Script: Build Predictable AI Agents

Anti-Patterns in Salesforce Agentforce: What to Avoid When Building AI Agents

MCP vs. Traditional APIs: Choosing the Right Integration Approach