You need to sign in to do that
Don't have an account?
Mahendiran Jayavarma
convert pageblocktable data into PDF adn send mail as attachment PDF
Hi,
If i am having pageblocktable and button control in a page.
when i click that button I need to send mail for pageblocktable records as a PDF format.
I tried like
<apex:page controller="sendEmail">
<apex:form>
<apex:pageblockTable value="{!Activities}" var="c" id="results" > <apex:column > <apex:facet name="header"> <apex:inputCheckBox value="{!selectAllCheckbox}" onclick="checkAll(this)"> <apex:actionSupport event="onclick" action="{!selectAll}" rerender="results"/> </apex:inputCheckBox> </apex:facet> <apex:inputCheckBox value="{!c.selected}"/> </apex:column> <apex:column value="{!c.acct.subject}"/> <apex:column value="{!c.acct.Id}"/> <apex:column value="{!c.acct.owner.name}"/> <apex:column value="{!c.acct.Billable_Hrs__c}"/> <apex:column value="{!c.acct.Rate_Hrs__c}"/> <apex:column value="{!c.acct.Billable_Amount__c}"/> </apex:pageblockTable>
<apex:commandbutton value="send mail" action="{!send}"/>
</apex:form>
</apex:page>
conroller:
public class sendEmail {
public PageReference send() {
// Define the email
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
// Take the PDF content
PageReference pdf = page.sendemail;
pdf.getParameters().get('results');
Blob b = pdf.getContent();
// Create the email attachment
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('attachment.pdf');
efa.setBody(b);
// Sets the paramaters of the email
email.setSubject( subject );
email.setToAddresses(new string[] {'mahe2682@gmail.com'});
email.setPlainTextBody( body );
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
// Sends the email
Messaging.SendEmailResult [] r =
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
}
}
actually It will generate pdf file but i could not open the file.
give me solution for how to resove it.
Thanks,
Mahendiran.
You can't pull back just a section of the page like that. You'll need to create a new page that has the renderAs attribute set to PDF and only contains the pageblocktable. You should be able to refactor the table out to a component so that you don't have to duplicate it.
can u send me sample.
thanks,
Mahendiran
I'm afraid I don't have a sample to send you. If you hit problems I'll endeavour to assist.
I done it. thanks for your support.
Hi Mahendiran,
Could you please share the code as to how were you able to crack it.
Thank you