You need to sign in to do that
Don't have an account?
Premanath
Creation of PDF file
Hi Guys,
I want to create a pdf of my vf page ,
we can create like this way
pdfPage = page.product_delivery;//new PageReference('/apex/product_delivery1');
pdfPage.getParameters().put('id',oppid);
pdfPage.setRedirect(false);
Blob b=pdfPage.getContentAsPDF();
In my vf i am displaying some records with checkbox. When i click on Selected Button , It is displaying Selected Records.
I want to Create PDF for Selected Records only.
But it is Generating PDF for my intial VF page..
please suggest me..
prem
see if this wud help
<apex:pageBlockTable value="{!products}" var="p" rendered="{!hide}">
<apex:column >
<apex:inputCheckbox value="{!p.selected}"/>
</apex:column>
<apex:column value="{!p.oli.PricebookEntry.Product2.Name}"/>
<apex:column value="{!p.oli.Quantity}"/>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Selected" action="{!Selected}" rerender="block2" oncomplete="sendmail"/>
<apex:actionfunction name="sendemail" action="{!SElectedSendemail}" />
<apex:pageBlockTable value="{!selectedprod}" var="p" rendered="{!show}" id="block2">
<apex:column >
<apex:inputCheckbox value="{!p.selected}"/>
</apex:column>
<apex:column value="{!p.oli.PricebookEntry.Product2.Name}"/>
<apex:column value="{!p.oli.Quantity}"/>
</apex:pageBlockTable>
</apex:pageBlockButtons>
All Answers
Hey prem,
Instead of generating a blob in the apex controller, have you tried using the 'renderAs' attribute for the apex:page tag in your product_delivery1 page? Something like this:
Then return the PageReference object rather than the blob in your apex method.
I want to Send a mail with attached pdf
Hi Gupta,
I am selecting Records from that Vf page only...
You can render any page as a PDF by adding therenderAsattribute to the<apex:page>component, and specifying “pdf” as the rendering service which salesforce already provided.
<apex: page renderAs = "pdf">
just create a button in vf page.
After selecting the records which you want as Pdf, then click on the button , it will convert to pdf.
for more reference use below link.
http://mindfiresfdcprofessionals.wordpress.com/2013/10/09/visualforce-page-that-renders-as-pdf-when-a-button-is-pushedclicked/
No man product_delivery only
Hi Rout,
I want to Download that PDF file and Need to send Email with that PDF file attachment.
How can i do that using renderAs
<apex:pageBlockTable value="{!products}" var="p">
<apex:column >
<apex:inputCheckbox value="{!p.selected}"/>
</apex:column>
<apex:column value="{!p.oli.PricebookEntry.Product2.Name}"/>
<apex:column value="{!p.oli.Quantity}"/>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Selected" action="{!Selected}"/>
</apex:pageBlockButtons>
public PageReference Selected(){
PageReference pdfPage ;
try{
outblock=true;
selectedprod= new List<OpportunityLineItem>();
for(cProduct eprod: getproducts()) {
if(eprod.selected == true){
selectedprod.add(eprod.oli);
}
}
System.Debug('*******************'+selectedprod);
pdfPage = page.product_delivery;//new PageReference('/apex/product_delivery1');
pdfPage.getParameters().put('id',oppid);
pdfPage.setRedirect(false);
Blob b=pdfPage.getContentAsPDF();
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName('deliverynote.pdf');
attach.setBody(b);
String[] toAddresses = new String[] {oppAcc.Account.Email__c};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(toAddresses);
mail.setSubject('Delivery note');
mail.setHtmlBody('Here is the email you requested! Check the attachment!');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
// Send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
Catch(Exception e){
}
return null;
}
see if this wud help
<apex:pageBlockTable value="{!products}" var="p" rendered="{!hide}">
<apex:column >
<apex:inputCheckbox value="{!p.selected}"/>
</apex:column>
<apex:column value="{!p.oli.PricebookEntry.Product2.Name}"/>
<apex:column value="{!p.oli.Quantity}"/>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Selected" action="{!Selected}" rerender="block2" oncomplete="sendmail"/>
<apex:actionfunction name="sendemail" action="{!SElectedSendemail}" />
<apex:pageBlockTable value="{!selectedprod}" var="p" rendered="{!show}" id="block2">
<apex:column >
<apex:inputCheckbox value="{!p.selected}"/>
</apex:column>
<apex:column value="{!p.oli.PricebookEntry.Product2.Name}"/>
<apex:column value="{!p.oli.Quantity}"/>
</apex:pageBlockTable>
</apex:pageBlockButtons>
Hi Gupta,
This is only the Better solution, i did some changes and finally i reached.
Thanks a lot,
Prem
Can you share the code .i am trying same thing but can not get it.
Thanks
<apex:pageBlockTable value="{!products}" var="p" rendered="{!hide}">
<apex:column >
<apex:inputCheckbox value="{!p.selected}"/>
</apex:column>
<apex:column value="{!p.oli.PricebookEntry.Product2.Name}"/>
<apex:column value="{!p.oli.Quantity}"/>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!selectedprod}" var="p" rendered="{!show}">
<apex:column value="{!p.PricebookEntry.Product2.Name}"/>
<apex:column value="{!p.Quantity}"/>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Selected" action="{!Selected}" oncomplete="sendmail();" reRender="pb"/>
</apex:pageBlockButtons>
<apex:actionfunction name="sendmail" action="{!SendAttach}" />
public PageReference Selected(){
show=true;
hide=false;
try{
selectedprod= new List<OpportunityLineItem>();
for(cProduct eprod: getproducts()) {
if(eprod.selected == true){
selectedprod.add(eprod.oli);
}
}
//System.Debug('*******************'+selectedprod);
//SendEmail();
}
Catch(Exception e){
}
return null;
}
public PageReference SendAttach(){
PageReference pdfPage ;
pdfPage = page.product_delivery;//new PageReference('/apex/product_delivery1');
pdfPage.getParameters().put('id',oppid);
pdfPage.setRedirect(false);
Blob b=pdfPage.getContentAsPDF();
// attach the pdf to the Opportunity
Attachment attach = new Attachment();
attach.Body = b;
attach.Name = 'deliverynote.pdf';
attach.ParentId = oppid;
insert attach;
}
I have only tried to create PDF files with the help of some PDF tools. You can also google it and select a PDF SDK whose way of processing is simple and fast to help you with the related work. Remember to check its free trial package first if possible. I hope you success. Good luck.
Best regards,
Arron