You need to sign in to do that
Don't have an account?
subodh chaturvedi 17
i want to generate my visualforce page in Pfd Format
Hi ,
I want to Generate my current visualforce page In Pdf Format when click on a Custom Button which is on the same page ,the class consist a wrapper class which has a checkbox & values , I have created a pagerefernce Method but how to generate in Pdf.
<apex:page standardController="Account" extensions="SolutionParticipationCategoryController" sidebar="False" >
<head>
<style type="text/css">
#rows{
padding-left:250px;
padding-Right:250px;
}
#cellAlign{
vertical-align: top;
border-collapse: collapse;
border: 1px solid black;
}
</style>
</head>
<apex:form >
<apex:sectionHeader title="Account" subtitle="Key Solutions Inventory "/>
<apex:pageBlock >
<apex:pageBlockbuttons >
<apex:commandButton value="Open Account" action="{!OpenAccount}"/>
<apex:commandButton value="Solution Participation " action="{!SolutionParticipation}" />
<apex:commandButton value="Card Program " action="{!cardProgram}" />
<apex:commandButton value="View Pdf" action="{!ViewPDF}"/>
</apex:pageBlockbuttons>
<table style="border-collapse: collapse;padding:50px;">
<tr>
<apex:repeat value="{!resultPickValuesMap}" var="M">
<td style="vertical-align: top;padding:30px;text-align:left;">
<b style="text-align:center;">{!M}</b><br/>
<apex:repeat value="{!resultPickValuesMap[M]}" var="temp">
<table>
<tr>
<td style="padding-top:5px;">
<apex:inputCheckbox value="{!temp.isSelected}" disabled="true"/>
<apex:commandLink id="theLink" action="{!solutionList}" target="_blank">
<apex:param assignTo="{!solName}" value="{!temp.value}" name="solName"/>
<apex:outputText value="{!temp.value}"/>
</apex:commandLink>
</td>
</tr>
</table>
</apex:repeat>
</td>
</apex:repeat>
</tr>
</table>
</apex:pageblock>
</apex:form>
</apex:page>
controller:-
/* *****
Date:- 8/1/2018
Description :- This Class is used to get the Multiselect Values from Account & displayed in New Vf Page on key solution Inventory button & checked
If altleast One Solution is Active so the Checkbox get checked.
*/
public with sharing class SolutionParticipationCategoryController
{
public Id acctId{get;set;}
public String solName{get;set;}
public Set<String> CategorySelected{get;set;}
Public MAP<String,LIST<Account>> accsCategoryByType{get;set;}
public Map<String, List<PicklistWrapper>> resultPickValuesMap{get;set;}
public Set<String> controllKeySet{get;set;}
public List<PicklistWrapper> enterpriseCardSolutionsList;
public List<PicklistWrapper> creditList;
public List<PicklistWrapper> debitList;
public List<PicklistWrapper> advisorsPlusList;
Public List<Solution_Participation__c>sp;
Public Integer count;
Public Map<String,Integer> checkActMap;
public SolutionParticipationCategoryController(ApexPages.StandardController stdController)
{
acctId = ApexPages.currentPage().getParameters().get('id');
System.debug('acctId-->'+acctId);
CategorySelected = new Set<String>();
resultPickValuesMap = getDependentOptionsImpl();
}
public Map<String,List<PicklistWrapper>> getDependentOptionsImpl()
{
String objApiName = 'Account';
String contrfieldApiName = 'Picklist_Independent__c';
String depfieldApiName = 'Solution_Participation_Category__c';
String objectName = objApiName.toLowerCase();
String controllingField = contrfieldApiName.toLowerCase();
String dependentField = depfieldApiName.toLowerCase();
checkActMap = new Map<String,Integer>();
Map<String,List<PicklistWrapper>> objResults = new Map<String,List<PicklistWrapper>>();
//get the string to sobject global map
Map<String,Schema.SObjectType> objGlobalMap = Schema.getGlobalDescribe();
if (!Schema.getGlobalDescribe().containsKey(objectName))
{
System.debug('OBJNAME NOT FOUND --.> ' + objectName);
return null;
}
Schema.SObjectType objType = Schema.getGlobalDescribe().get(objectName);
if (objType==null){
return objResults;
}
Bitset bitSetObj = new Bitset();
Map<String, Schema.SObjectField> objFieldMap = objType.getDescribe().fields.getMap();
//Check if picklist values exist
if (!objFieldMap.containsKey(controllingField) || !objFieldMap.containsKey(dependentField)){
System.debug('FIELD NOT FOUND --.> ' + controllingField + ' OR ' + dependentField);
return objResults;
}
List<Schema.PicklistEntry> contrEntries = objFieldMap.get(controllingField).getDescribe().getPicklistValues();
List<Schema.PicklistEntry> depEntries = objFieldMap.get(dependentField).getDescribe().getPicklistValues();
objFieldMap = null;
List<Integer> controllingIndexes = new List<Integer>();
for(Integer contrIndex=0; contrIndex<contrEntries.size(); contrIndex++) {
Schema.PicklistEntry ctrlentry = contrEntries[contrIndex];
String label = ctrlentry.getLabel();
objResults.put(label,new List<PicklistWrapper>());
controllingIndexes.add(contrIndex);
}
List<Schema.PicklistEntry> objEntries = new List<Schema.PicklistEntry>();
List<PicklistEntryWrapper> objJsonEntries = new List<PicklistEntryWrapper>();
for(Integer dependentIndex=0; dependentIndex<depEntries.size(); dependentIndex++){
Schema.PicklistEntry depentry = depEntries[dependentIndex];
objEntries.add(depentry);
}
objJsonEntries = (List<PicklistEntryWrapper>)JSON.deserialize(JSON.serialize(objEntries), List<PicklistEntryWrapper>.class);
List<Integer> indexes;
Account a = [SELECT Solution_Participation_Category__c,(SELECT Id,solution_name__c,Active__c FROM solution_participations__r) FROM Account WHERE Id =: acctId limit 1];
List<Solution_Participation__c> mySol = a.solution_participations__r;
Schema.DescribeFieldResult fieldResult = Account.Solution_Participation_Category__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for(PicklistEntryWrapper pew : objJsonEntries){
count=0;
for(Solution_Participation__c solp:mySol){
if(solp.Active__c==true && solp.solution_name__c==String.valueof(pew.label)){
count++;
checkActMap.put(String.valueof(pew.label),count);
}
}
}
if(a.Solution_Participation_Category__c != null )
{
CategorySelected.addAll(a.Solution_Participation_Category__c.split(';'));
}
//Schema.DescribeFieldResult fieldResult = Account.Solution_Participation_Category__c.getDescribe();
//List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for (PicklistEntryWrapper objJson : objJsonEntries){
if (objJson.validFor==null || objJson.validFor==''){
continue;
}
indexes = bitSetObj.testBits(objJson.validFor,controllingIndexes);
sp= [select Id,Active__c, Account__r.Solution_Participation_Category__c From Solution_Participation__c where Account__c =: acctId limit 1];
for (Integer idx : indexes)
{
String contrLabel = contrEntries[idx].getLabel();
if(CategorySelected.contains(String.valueof(objJson.label))&&checkActMap.get(String.valueof(objJson.label))>0)
{
objResults.get(contrLabel).add(new PicklistWrapper(objJson.label,true));
}
else
{
objResults.get(contrLabel).add(new PicklistWrapper(objJson.label,false));
}
}
}
objEntries = null;
objJsonEntries = null;
system.debug('objResults--->' + objResults);
return objResults;
}
public class PicklistWrapper
{
public String value {get;set;}
public Boolean isSelected {get;set;}
public PicklistWrapper(String value, Boolean isSelected)
{
this.value = value;
this.isSelected = isSelected;
}
}
public PageReference solutionList()
{
System.debug('SolName-->'+solName);
PageReference solutionList = new Pagereference('/apex/SolutionList');
solutionList.getParameters().put('Id', acctId);
solutionList.getParameters().put('solName', solName);
solutionList.setRedirect(true);
return solutionList;
}
public PageReference OpenAccount()
{
Pagereference acc = new Pagereference('/'+acctId);
acc.setRedirect(true);
return acc;
}
Public PageReference SolutionParticipation()
{
id ReportId = [Select id from Report where name = 'Solution Participants'].id;
Pagereference sp= new Pagereference('/'+ReportId);
sp.setRedirect(true);
return sp;
}
Public PageReference CardProgram()
{
id ReportId1 = [Select id from Report where name = 'Card Programs'].id;
Pagereference cp= new Pagereference('/'+ReportId1);
cp.setRedirect(true);
return cp;
}
/* Public PageReference ViewPDF(){
pageReference vpdf = page.solutionparticipationPDF;
vpdf.setRedirect(true);
return vpdf;
}*/
}
I want to Generate my current visualforce page In Pdf Format when click on a Custom Button which is on the same page ,the class consist a wrapper class which has a checkbox & values , I have created a pagerefernce Method but how to generate in Pdf.
<apex:page standardController="Account" extensions="SolutionParticipationCategoryController" sidebar="False" >
<head>
<style type="text/css">
#rows{
padding-left:250px;
padding-Right:250px;
}
#cellAlign{
vertical-align: top;
border-collapse: collapse;
border: 1px solid black;
}
</style>
</head>
<apex:form >
<apex:sectionHeader title="Account" subtitle="Key Solutions Inventory "/>
<apex:pageBlock >
<apex:pageBlockbuttons >
<apex:commandButton value="Open Account" action="{!OpenAccount}"/>
<apex:commandButton value="Solution Participation " action="{!SolutionParticipation}" />
<apex:commandButton value="Card Program " action="{!cardProgram}" />
<apex:commandButton value="View Pdf" action="{!ViewPDF}"/>
</apex:pageBlockbuttons>
<table style="border-collapse: collapse;padding:50px;">
<tr>
<apex:repeat value="{!resultPickValuesMap}" var="M">
<td style="vertical-align: top;padding:30px;text-align:left;">
<b style="text-align:center;">{!M}</b><br/>
<apex:repeat value="{!resultPickValuesMap[M]}" var="temp">
<table>
<tr>
<td style="padding-top:5px;">
<apex:inputCheckbox value="{!temp.isSelected}" disabled="true"/>
<apex:commandLink id="theLink" action="{!solutionList}" target="_blank">
<apex:param assignTo="{!solName}" value="{!temp.value}" name="solName"/>
<apex:outputText value="{!temp.value}"/>
</apex:commandLink>
</td>
</tr>
</table>
</apex:repeat>
</td>
</apex:repeat>
</tr>
</table>
</apex:pageblock>
</apex:form>
</apex:page>
controller:-
/* *****
Date:- 8/1/2018
Description :- This Class is used to get the Multiselect Values from Account & displayed in New Vf Page on key solution Inventory button & checked
If altleast One Solution is Active so the Checkbox get checked.
*/
public with sharing class SolutionParticipationCategoryController
{
public Id acctId{get;set;}
public String solName{get;set;}
public Set<String> CategorySelected{get;set;}
Public MAP<String,LIST<Account>> accsCategoryByType{get;set;}
public Map<String, List<PicklistWrapper>> resultPickValuesMap{get;set;}
public Set<String> controllKeySet{get;set;}
public List<PicklistWrapper> enterpriseCardSolutionsList;
public List<PicklistWrapper> creditList;
public List<PicklistWrapper> debitList;
public List<PicklistWrapper> advisorsPlusList;
Public List<Solution_Participation__c>sp;
Public Integer count;
Public Map<String,Integer> checkActMap;
public SolutionParticipationCategoryController(ApexPages.StandardController stdController)
{
acctId = ApexPages.currentPage().getParameters().get('id');
System.debug('acctId-->'+acctId);
CategorySelected = new Set<String>();
resultPickValuesMap = getDependentOptionsImpl();
}
public Map<String,List<PicklistWrapper>> getDependentOptionsImpl()
{
String objApiName = 'Account';
String contrfieldApiName = 'Picklist_Independent__c';
String depfieldApiName = 'Solution_Participation_Category__c';
String objectName = objApiName.toLowerCase();
String controllingField = contrfieldApiName.toLowerCase();
String dependentField = depfieldApiName.toLowerCase();
checkActMap = new Map<String,Integer>();
Map<String,List<PicklistWrapper>> objResults = new Map<String,List<PicklistWrapper>>();
//get the string to sobject global map
Map<String,Schema.SObjectType> objGlobalMap = Schema.getGlobalDescribe();
if (!Schema.getGlobalDescribe().containsKey(objectName))
{
System.debug('OBJNAME NOT FOUND --.> ' + objectName);
return null;
}
Schema.SObjectType objType = Schema.getGlobalDescribe().get(objectName);
if (objType==null){
return objResults;
}
Bitset bitSetObj = new Bitset();
Map<String, Schema.SObjectField> objFieldMap = objType.getDescribe().fields.getMap();
//Check if picklist values exist
if (!objFieldMap.containsKey(controllingField) || !objFieldMap.containsKey(dependentField)){
System.debug('FIELD NOT FOUND --.> ' + controllingField + ' OR ' + dependentField);
return objResults;
}
List<Schema.PicklistEntry> contrEntries = objFieldMap.get(controllingField).getDescribe().getPicklistValues();
List<Schema.PicklistEntry> depEntries = objFieldMap.get(dependentField).getDescribe().getPicklistValues();
objFieldMap = null;
List<Integer> controllingIndexes = new List<Integer>();
for(Integer contrIndex=0; contrIndex<contrEntries.size(); contrIndex++) {
Schema.PicklistEntry ctrlentry = contrEntries[contrIndex];
String label = ctrlentry.getLabel();
objResults.put(label,new List<PicklistWrapper>());
controllingIndexes.add(contrIndex);
}
List<Schema.PicklistEntry> objEntries = new List<Schema.PicklistEntry>();
List<PicklistEntryWrapper> objJsonEntries = new List<PicklistEntryWrapper>();
for(Integer dependentIndex=0; dependentIndex<depEntries.size(); dependentIndex++){
Schema.PicklistEntry depentry = depEntries[dependentIndex];
objEntries.add(depentry);
}
objJsonEntries = (List<PicklistEntryWrapper>)JSON.deserialize(JSON.serialize(objEntries), List<PicklistEntryWrapper>.class);
List<Integer> indexes;
Account a = [SELECT Solution_Participation_Category__c,(SELECT Id,solution_name__c,Active__c FROM solution_participations__r) FROM Account WHERE Id =: acctId limit 1];
List<Solution_Participation__c> mySol = a.solution_participations__r;
Schema.DescribeFieldResult fieldResult = Account.Solution_Participation_Category__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for(PicklistEntryWrapper pew : objJsonEntries){
count=0;
for(Solution_Participation__c solp:mySol){
if(solp.Active__c==true && solp.solution_name__c==String.valueof(pew.label)){
count++;
checkActMap.put(String.valueof(pew.label),count);
}
}
}
if(a.Solution_Participation_Category__c != null )
{
CategorySelected.addAll(a.Solution_Participation_Category__c.split(';'));
}
//Schema.DescribeFieldResult fieldResult = Account.Solution_Participation_Category__c.getDescribe();
//List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for (PicklistEntryWrapper objJson : objJsonEntries){
if (objJson.validFor==null || objJson.validFor==''){
continue;
}
indexes = bitSetObj.testBits(objJson.validFor,controllingIndexes);
sp= [select Id,Active__c, Account__r.Solution_Participation_Category__c From Solution_Participation__c where Account__c =: acctId limit 1];
for (Integer idx : indexes)
{
String contrLabel = contrEntries[idx].getLabel();
if(CategorySelected.contains(String.valueof(objJson.label))&&checkActMap.get(String.valueof(objJson.label))>0)
{
objResults.get(contrLabel).add(new PicklistWrapper(objJson.label,true));
}
else
{
objResults.get(contrLabel).add(new PicklistWrapper(objJson.label,false));
}
}
}
objEntries = null;
objJsonEntries = null;
system.debug('objResults--->' + objResults);
return objResults;
}
public class PicklistWrapper
{
public String value {get;set;}
public Boolean isSelected {get;set;}
public PicklistWrapper(String value, Boolean isSelected)
{
this.value = value;
this.isSelected = isSelected;
}
}
public PageReference solutionList()
{
System.debug('SolName-->'+solName);
PageReference solutionList = new Pagereference('/apex/SolutionList');
solutionList.getParameters().put('Id', acctId);
solutionList.getParameters().put('solName', solName);
solutionList.setRedirect(true);
return solutionList;
}
public PageReference OpenAccount()
{
Pagereference acc = new Pagereference('/'+acctId);
acc.setRedirect(true);
return acc;
}
Public PageReference SolutionParticipation()
{
id ReportId = [Select id from Report where name = 'Solution Participants'].id;
Pagereference sp= new Pagereference('/'+ReportId);
sp.setRedirect(true);
return sp;
}
Public PageReference CardProgram()
{
id ReportId1 = [Select id from Report where name = 'Card Programs'].id;
Pagereference cp= new Pagereference('/'+ReportId1);
cp.setRedirect(true);
return cp;
}
/* Public PageReference ViewPDF(){
pageReference vpdf = page.solutionparticipationPDF;
vpdf.setRedirect(true);
return vpdf;
}*/
}
From the VF Developer Guide (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_renderas_pdf.htm) -
You can render any page as a PDF by adding the renderAs attribute to the <apex:page> component, and specifying “pdf” as the rendering service. For example:
<apex:page renderAs="pdf">
Does this help? Do read and let me know if you need more clarification.
--
Abhi