1

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:

sc

Things that didn't work.

  • I set the <apex:pageBlockTable style="width:60%;"> - It reduces the width of table in VF page but not in PDF.
  • I set the column widths for each individual columns <apex:pageBlockTable columnsWidth="10%,10%,10%">
  • I reduced the cell padding <apex:pageBlockTable cellPadding="1">
  • I tried zooming out the table. It zooms out for VF page but not for PDF attachment.
  • I tried reducing the side margins of the PDF file. After putting negative margin to the table through css, the first column gets cutoff but the margin of the PDF file does not disappear.
  • sc2

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.
    }
6
  • 1
    Did you try to set max-width for some of the columns?
    – Liron C
    Jan 27, 2021 at 10:00
  • @LironC Thanks for the response! I just tried setting max-width as follows <apex:column headerValue="Product Type" value="{!Rate.ProdType}" style="max-width: 10px;"/> . I set this to all columns except the last one. It worked on the VF page but not on the PDF file. The last column is still getting cutoff in the PDF attachment.
    – Koustubh
    Jan 27, 2021 at 10:14
  • 1
    You have too many columns to work even in landscape mode. Try using a smaller font, multiple rows via the breakBefore attribute, or include fewer columns.
    – sfdcfox
    Jan 27, 2021 at 12:56
  • @sfdcfox Thanks for the suggestions! I reduced the font size by 10% and it worked.
    – Koustubh
    Jan 27, 2021 at 14:37
  • @sfdcfox I have a question related to this. Please guide. Thank You! salesforce.stackexchange.com/questions/332609/…
    – Koustubh
    Jan 28, 2021 at 9:20

0

You must log in to answer this question.