Print the details of page in pdf using Visualforce page in Salesforce

By | November 26, 2019

Hi, here we have shown, how to print the account details in pdf manner using visualforce page.

Print page will contain the detail account records & related object fields in the pdf.

Apex controller

public class PrintView {
    public List<Account> acclist{get;set;}
    public String SelectAccId{get;set;}
    public PrintView(){
        DisplayAccount();
    }
    public void DisplayAccount(){
        acclist = new List<Account>();
        acclist = [SELECT Name,Id,Rating,Phone FROM Account];// add required fields to print 
    }
}

Vf Page

<apex:page controller="PrintView" >
    <apex:form >
        <apex:pageBlock id="pbList">
            <apex:pageBlockTable value="{!acclist}" var="a" rendered="true">
                <apex:column value="{!a.Name}"/>                    
                <apex:column value="{!a.Phone}"/>                   
                <apex:column value="{!a.Rating}"/>                    
                <apex:column >
                    <apex:facet name="header">Print</apex:facet>
                    <apex:outputlink value="/{!a.Id}/p?retURL=/{!a.Id}" target="_blank">Print</apex:outputlink>                    
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Output

when we click on print, print page will be open in another window.

Leave a Reply

Your email address will not be published. Required fields are marked *