Salesforce Asked by SFdev on February 24, 2021
I wish to send a visualforce page as an email PDF attachment to user. The problem I am facing is that the columns don’t fit in the PDF. Hence I sent the PDF in landscape mode. After that, some extra columns fit but not all.
I need to fit one extra column in the PDF attachment. Please guide. Thank You!
Screenshot:
Things that didn’t work.
<apex:pageBlockTable style="width:60%;">
– It reduces the width of table in VF page but not in PDF.<apex:pageBlockTable columnsWidth="10%,10%,10%">
<apex:pageBlockTable cellPadding="1">
VF Page Datatable Code.
<apex:pageBlockSection Title="Rate Profile" columns="1" rendered="{!RateListTable.size!=0}" collapsible="True">
<apex:pageBlockTable value="{!RateListTable}" var="Rate" id="RateTable" style="width:100%;" cellPadding="4" border="1" >
<apex:column headerValue="Product Type" value="{!Rate.ProdType}" />
<apex:column headerValue="Service Type" value="{!Rate.ServiceType}" />
<apex:column headerValue="Category" value="{!Rate.Category}" />
<apex:column headerValue="Usage Type" value="{!Rate.UsageType}" />
<apex:column headerValue="MDM ID" value="{!Rate.ProdMDMID}" />
<apex:column headerValue="Product Name" value="{!Rate.ProdName}" />
<apex:column headerValue="Delineation" value="{!Rate.DelType}" />
<apex:column headerValue="Delineation Value" value="{!Rate.DelVal1}" />
<apex:column headerValue="From" value="{!Rate.FromVal}" />
<apex:column headerValue="To" value="{!Rate.To}" />
<apex:column headerValue="Rate" value="{!Rate.Rate}" />
<apex:column headerValue="Rate Frequency" value="{!Rate.RateFreq}" />
<apex:column headerValue="PPA" value="{!Rate.PPA}" />
<apex:column headerValue="Message" value="{!Rate.Message}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
Code to send email.
public PageReference EmailRateSheet() {
PageReference rateProfile = ApexPages.currentPage(); //get the current page reference
rateProfile.setRedirect(true); //set the redirect property to true to avoid the page resubmission warning
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment(); //create attachment
attachment.setFileName('RateProfile for ' + CustomerRec.Name + '.pdf'); //set the file name of attachment
attachment.setBody(rateProfile.getContentAsPDF()); //set the pdf version of the page in body of the attachment
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); //create SingleEmailMessage object
message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } ); //set the attachment to the email
message.setSubject('Rate sheet for ' + CustomerRec.Name); //set subject of the email
message.setHTMLBody('Hi '+ userInfo.getFirstName() + ', <p>' +' The Rate sheet for <b>' + CustomerRec.Name + '</b> is attached. <p> Regards,<P> Salesforce Team'); //set body of the email
message.setToAddresses( new String[] { UserInfo.getUserEmail() } ); //set the email address of the logged-in user as recipient address
Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } ); //send the email
return rateProfile; //return the page reference. If you return null, page resubmission warning will appear on refreshing the page.
}
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP