You need to sign in to do that
Don't have an account?

How to display selected account record as a pdf format
Hi, Friends
I want to display selected Account record as pdf format when I select the checkboxes those records only displayed in pdf format. I tried this scenario but the page has not displayed the content of the record. it displays only empty pdf page. Please go through the following code which i had developed in my org. Please let me know what mistake I had made in the code.
Controller
public class PdfController {
public List<Account> initialList {get;set;}
public List<Account> selectedlist {get;set;}
public List<InnerWrapper> wlist {get;set;}
public PdfController() {
initialList=new List<Account>();
wlist=new List<InnerWrapper>();
InnerWrapper iw;
initialList=[SELECT Id, Name, Industry FROM Account LIMIT 10];
for(Account a:initialList){
iw=new InnerWrapper();
iw.unselected=a;
wlist.add(iw);
}
}
public PageReference displaySelected() {
selectedlist=new List<Account>();
for(InnerWrapper selectedaccount:wlist){
if(selectedaccount.selectacc){
selectedlist.add(selectedaccount.unselected);
}
}
PageReference p=page.pdfpage;
return p;
}
public class InnerWrapper {
public boolean selectacc{get;set;}
public Account unselected {get;set;}
}
}
Vfpage1
<apex:page controller="PdfController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable title="Accounts" value="{!wlist}" var="iterate">
<apex:column headerValue="selectAccount">
<apex:inputCheckbox value="{!iterate.selectacc}"/>
</apex:column>
<apex:column headerValue="Name" value="{!iterate.unselected.Name}"/>
<apex:column headerValue="Print">
<apex:commandButton value="download" action="{!displaySelected}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page controller="PdfController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable title="Accounts" value="{!wlist}" var="iterate">
<apex:column headerValue="selectAccount">
<apex:inputCheckbox value="{!iterate.selectacc}"/>
</apex:column>
<apex:column headerValue="Name" value="{!iterate.unselected.Name}"/>
<apex:column headerValue="Print">
<apex:commandButton value="download" action="{!displaySelected}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Vfpage2
<apex:page controller="PdfController" showHeader="false">
<apex:pageBlock >
<apex:pageBlockTable value="{!selectedlist}" var="a">
<apex:pageBlockSection columns="2">
<apex:outputField value="{!a.Name}"/>
</apex:pageBlockSection>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
I want to display selected Account record as pdf format when I select the checkboxes those records only displayed in pdf format. I tried this scenario but the page has not displayed the content of the record. it displays only empty pdf page. Please go through the following code which i had developed in my org. Please let me know what mistake I had made in the code.
Controller
public class PdfController {
public List<Account> initialList {get;set;}
public List<Account> selectedlist {get;set;}
public List<InnerWrapper> wlist {get;set;}
public PdfController() {
initialList=new List<Account>();
wlist=new List<InnerWrapper>();
InnerWrapper iw;
initialList=[SELECT Id, Name, Industry FROM Account LIMIT 10];
for(Account a:initialList){
iw=new InnerWrapper();
iw.unselected=a;
wlist.add(iw);
}
}
public PageReference displaySelected() {
selectedlist=new List<Account>();
for(InnerWrapper selectedaccount:wlist){
if(selectedaccount.selectacc){
selectedlist.add(selectedaccount.unselected);
}
}
PageReference p=page.pdfpage;
return p;
}
public class InnerWrapper {
public boolean selectacc{get;set;}
public Account unselected {get;set;}
}
}
Vfpage1
<apex:page controller="PdfController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable title="Accounts" value="{!wlist}" var="iterate">
<apex:column headerValue="selectAccount">
<apex:inputCheckbox value="{!iterate.selectacc}"/>
</apex:column>
<apex:column headerValue="Name" value="{!iterate.unselected.Name}"/>
<apex:column headerValue="Print">
<apex:commandButton value="download" action="{!displaySelected}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page controller="PdfController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable title="Accounts" value="{!wlist}" var="iterate">
<apex:column headerValue="selectAccount">
<apex:inputCheckbox value="{!iterate.selectacc}"/>
</apex:column>
<apex:column headerValue="Name" value="{!iterate.unselected.Name}"/>
<apex:column headerValue="Print">
<apex:commandButton value="download" action="{!displaySelected}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Vfpage2
<apex:page controller="PdfController" showHeader="false">
<apex:pageBlock >
<apex:pageBlockTable value="{!selectedlist}" var="a">
<apex:pageBlockSection columns="2">
<apex:outputField value="{!a.Name}"/>
</apex:pageBlockSection>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
You will need Apex class (Controller Extension) and Visualforce page.
1. Create a Custom Button of type List and add on List View. The URL of the button should be your Visualforce page.
2. When you select the contacts and click on "Your Custom Button", the ID of selected Contacts will be available to your Controller Extension.
3. Populate all your record in Visual force and tell render as pdf.
That's it.
If you need a tutorial on how to create PDF, please look into below article:
- http://wiki.developerforce.com/page/Creating_Professional_PDF_Documents_with_CSS_and_Visualforce
Let's take an example of Lead.Visual Force Page: Apex Controller Page: Please let us know if this helps.
Regards,
Nagendra.
Use <apex:page controller="PdfController" renderAs="pdf"> in vf page. It will for you.
page
<apex:page standardController="Lead" recordSetVar="leads" extensions="LeadPdfCon" renderAs="pdf">
<apex:form>
<apex:pageBlock>
<apex:pageBlockTable value="{!leads}" var="led">
<apex:outputText value="{!led.LastName}"></apex:outputText>
<apex:outputText value="{!led.status}"></apex:outputText>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Seems everything fine with your visual force page.may I request you to please post the extension "LeadPdfCon" controller so that we can look into it and do the needful.
Regards,
Nagendra.
I am using the same code that you are posted.
public class LeadPdfCon {
ApexPages.StandardSetController setcon;
Public list<Lead> listtodisplay{get;set;}
public LeadPdfCon(ApexPages.StandardSetController controller){
setcon=controller;
Set<Id> leadIdSet=new Set<Id>();
for(Lead l:(Lead[])setcon.getSelected()){
leadIdSet.add(l.Id);
}
}
}
I am grateful to you for your quick response.