function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sankar GaneshSankar Ganesh 

How to remove last blank page in visualforce while renderas pdf

I am getting last page as  a blank page while using renderas PDF. I used  Style="page-break-inside:avoid;page-break-after:auto ; but still I am getting blank page. Kindly suggest me how to solve this .
 
<head>
       <style type="text/css" media="print">
           @page {
                   margin-top: 5.0cm;
                   margin-left: 1.0cm;
                   margin-bottom: 30px;
                   margin-right: 1.0cm;      
                   
            
                     @top-center {
                                 content: element(header);
                                 }
                     @bottom-left {
                                 content: element(footer);
                                  }
               }
                  div.header {
                              position: running(header);
                             
                             }
                   div.footer{
                              
                                page-break-after:avoid;
                                page-break-inside:avoid;
                                position: running(footer);
                             }          
                     
               
                        #table1{
                          border-collapse: collapse;
                          
                        }
                        #table1 td{
                           border:1px solid black;
                           padding:5px;
                        }
                       
                      
                                    
        </style>
     </head>

I am facing this problem for below code
 
<div class="footer">
   <table width="100%">
    <tr>
       <td align="center">footer content here</td>
    </tr>
   </table>
  </div>
 

 <div>
   <apex:variable var="count" value="{!0}" />
    <table id="table1" width="100%">
       <tr id="hrow1">
            <td align="center" width="27%" ><b>Item</b></td>
            <td align="center" width="40%"><b>Description</b></td>
            <td align="center" width="8%"><b>Qty</b></td>
            <td align="center" width="10%"><b>Cost</b></td>
            <td align="center" width="15%"><b>Total</b></td>
       </tr>
        <apex:repeat value="{!Quote.QuoteLineItems}" var="line" >
          <tr>
            <td><b><apex:outputText value="{!line.Product2.Name}"/></b></td>
            <td><apex:outputText value="{!line.Line_Item_Description__c}" escape="false"/></td>
            <td><apex:outputField value="{!line.Quantity}"/></td>
            <td > <apex:outputText value="{0, number, ###,###,###,##0.00}">  <apex:param value="{!line.UnitPrice}" /> </apex:outputText></td>
            <td> <b>  <apex:outputText value="{0, number, ###,###,###,##0.00}">  <apex:param value="{!line.TotalPrice}" /> </apex:outputText> </b></td>
        </tr>
        <apex:variable var="count" value="{!count+1}"/>
       </apex:repeat>
       <tr style="page-break-inside:avoid;"> 
           <td colspan="6" style="border-top:none;" >&nbsp; </td>
       </tr> 
    </table>
        
     <table width="100%" style="border-collapse: collapse;page-break-inside:avoid;page-break-after:auto;">
          <tr>
             <td colspan="2">{!Quote.Customer_Message__c}</td>
             <td colspan="2" align="right" ><b> Total:</b></td>
             <td align="right"><b><apex:outputField value="{!Quote.TotalPrice}"/></b></td>
       
         </tr> 
     </table>
   
 </div>

 
Raj VakatiRaj Vakati
Update your styles as below. Can you pls share complete code to see the issue.
 
@page {
            margin-top: 5.0cm;
            margin-left: 1.0cm;
            margin-bottom: 30px;
            margin-right: 1.0cm;      
         page-break:always; page-break-inside:avoid;
            
            @top-center {
            content: element(header);
            }
            @bottom-left {
            content: element(footer);
            }
            }

 
Sankar GaneshSankar Ganesh
@Raj V

I tried your style but that also not working. Here is my full code.
 
<apex:page showheader="false" standardController="Quote" renderAs="pdf" applyHtmlTag="false">
  <head>
       <style type="text/css" media="print">
           @page {
                   margin-top: 5.0cm;
                   margin-left: 1.0cm;
                   margin-bottom: 48px;
                   margin-right: 1.0cm;      
                   
            
                     @top-center {
                                 content: element(header);
                                 }
                     @bottom-left {
                                 content: element(footer);
                                  }
               }
                  div.header {
                              position: running(header);
                             
                             }
                   div.footer{
                              
                               page-break-after:avoid;
                               page-break-before:avoid;                           
                                page-break-inside:avoid;
                                position: running(footer);
                             }          
                     
                  .start{
                          font-size:10pt;
                          font-family:sans-serif;
                        }
                        #table1{
                          border-collapse: collapse;
                          
                        }
                        #table1 td{
                           border:1px solid black;
                           padding:5px;
                        }
                        #hrow1 {
                          background-color: #e5e5e5;
                        }
                                    
                    </style>
              </head>
              
<body class="start">
 <div class="header">
  <table style="border-collapse: collapse;" border="" >
    <tr>
        <td width="40%"  ><apex:image value="{!$Resource.logo}" width="300" /> </td>
   
        <td valign="bottom" style="padding-right:50px;"  >
           <table border="" style="border-collapse: collapse;"  width="60%" align="right">
              <tr>
                 <td width="60%" > <apex:image value="{!$Resource.proposal}" /></td>
                 <td></td>
              </tr>
              <tr>
                 <td width="30%" >Proposal Date</td>
                 <td width="30%" align="left"><apex:outputField value="{!Quote.Quote_Date__c}"/></td>
              </tr>
              <tr>
                 <td >Expiration Date</td>
                 <td align="left"><apex:outputField value="{!Quote.ExpirationDate}"/></td>
              </tr>
               <tr>
                 <td >Proposal No.</td>
                 <td align="left">{!RIGHT(Quote.QuoteNumber,5)}</td>
              </tr>
          </table>  
       </td>    
     </tr>
   </table>  
  </div>
  <div class="footer">
    <table width="100%">
    <tr>
       <td align="center">single line footer content here</td>
    </tr>
    </table>
  </div>
  <div >
    <table  width="100%" border="" style="border-collapse: collapse;" > 
      <tr>
         <td style="border:1px solid black;font-size:16px;border-top:none;border-right:none;border-left:none;">&nbsp;&nbsp;<b>Customer:</b> </td>
        <td> &nbsp;</td> 
         <td style="border:1px solid black;font-size:16px;border-top:none;border-right:none;border-left:none;">&nbsp;&nbsp;<b>Ship To:</b> </td>
      </tr>
      <tr>
         <td height="80" width="320" style="border:1px solid black;border-top:none;border-right:none;border-left:none;border-bottom:none;" valign="top">  
             
             <b> <apex:outputText value="{!Quote.BillingName}" rendered="{!Quote.BillingName!=null}"><br/></apex:outputText> 
                 <apex:outputText value="{!Quote.Contact.Name}" rendered="{!Quote.Contact.Name!=null}"><br/></apex:outputText> 
                 <apex:outputText value="{!Quote.BillingStreet}" rendered="{!Quote.BillingStreet!=null}"><br/></apex:outputText>
                <apex:outputText value="{!Quote.BillingCity}" rendered="{!Quote.BillingCity!=null}"><br/></apex:outputText>
                <apex:outputText value="{!Quote.BillingState}" rendered="{!Quote.BillingState!=null}">,&nbsp;</apex:outputText> 
                <apex:outputText value="{!Quote.BillingPostalCode}" rendered="{!Quote.BillingPostalCode!=null}">,&nbsp;</apex:outputText>
                <apex:outputText value="{!Quote.BillingCountry}" rendered="{!Quote.BillingCountry!=null}"><br/></apex:outputText>
             </b>
                 
         </td>
         <td width="20"></td> 
         <td height="80" width="320" style="border:1px solid black;border-top:none;border-right:none;border-left:none;border-bottom:none;"  valign="top">  
               <b> <apex:outputText value="{!Quote.ShippingName}" rendered="{!Quote.ShippingName!=null}"><br/></apex:outputText> 
                 <apex:outputText value="{!Quote.ShippingStreet}" rendered="{!Quote.ShippingStreet!=null}"><br/></apex:outputText>
                <apex:outputText value="{!Quote.ShippingCity}" rendered="{!Quote.ShippingCity!=null}"><br/></apex:outputText>
                <apex:outputText value="{!Quote.ShippingState}" rendered="{!Quote.ShippingState!=null}">,&nbsp;</apex:outputText> 
                <apex:outputText value="{!Quote.ShippingPostalCode}" rendered="{!Quote.ShippingPostalCode!=null}">,&nbsp;</apex:outputText>
                <apex:outputText value="{!Quote.ShippingCountry}" rendered="{!Quote.ShippingCountry!=null}"><br/></apex:outputText>
             </b>
            
         </td>
      </tr>
  </table>
 </div>
 <div style="padding-top:20px">
    <table width="100%" border="">
        <tr>
             <td width="25%">&nbsp;&nbsp;<u>Attention:</u> </td>
             <td width="30%"><u>{!Quote.Attention__c}</u> </td>
             <td width="20%">Sales Person: </td>
             <td width="25%"> <apex:outputField value="{!Quote.Sales_Person__r.Name}" /></td>
             
        </tr>
        <tr>
             <td width="25%">&nbsp;&nbsp;Free On Board: </td>
             <td width="30%"><apex:outputField value="{!Quote.Free_on__c}" /> </td>
             <td width="20%">Payment Terms:</td>
             <td width="25%"> <apex:outputField value="{!Quote.Payment_Terms__c}" /></td>
             
        </tr>
        <tr>
             <td width="25%">&nbsp;&nbsp;Ship Via: </td>
             <td width="30%"><apex:outputField value="{!Quote.Ship_Via__c}" /> </td>
             <td width="20%">Lead Time: </td>
             <td width="25%"> <apex:outputField value="{!Quote.Lead_Time__c}" /></td>
             
        </tr>
    </table>
 </div>
 <div >
   <apex:variable var="count" value="{!0}" />
    <table id="table1" width="100%">
       <tr id="hrow1">
            <td align="center" width="27%" ><b>Item</b></td>
            <td align="center" width="40%"><b>Description</b></td>
            <td align="center" width="8%"><b>Qty</b></td>
            <td align="center" width="10%"><b>Cost</b></td>
            <td align="center" width="15%"><b>Total</b></td>
       </tr>
        <apex:repeat value="{!Quote.QuoteLineItems}" var="line" >
          <tr style="background-color:{!IF(mod(count,2)==0, 'white','#e0e0e0')};">
            <td valign="top" style="border-bottom:none;border-top:none;border-right-color:{!IF(mod(count,2)==0, '','#ffffff')};border-right:{!IF(mod(count,2)==0,'none','')};">
              <b><apex:outputText value="{!line.Product2.Name}"/></b></td>
            <td valign="top" style="border-bottom:none;border-left:none;border-top:none;border-right-color:{!IF(mod(count,2)==0, '#ffffff','#ffffff')};border-right:{!IF(mod(count,2)==0,'none','')};"><apex:outputText value="{!line.Line_Item_Description__c}" escape="false"/></td>
            <td valign="top" align="center" style="border-bottom:none;border-left:none;border-top:none;border-right-color:{!IF(mod(count,2)==0, '#ffffff','#ffffff')};border-right:{!IF(mod(count,2)==0,'none','')};"><apex:outputField value="{!line.Quantity}"/></td>
            <td valign="top" align="right" style="border-bottom:none;border-left:none;border-top:none;border-right-color:{!IF(mod(count,2)==0, '#ffffff','#ffffff')};border-right:{!IF(mod(count,2)==0,'none','')};">
                <apex:outputText value="{0, number, ###,###,###,##0.00}">  <apex:param value="{!line.UnitPrice}" /> </apex:outputText>
            </td>
            <td valign="top" align="right" style="border-bottom:none;border-left:none;border-top:none;">
              <b>  <apex:outputText value="{0, number, ###,###,###,##0.00}">  <apex:param value="{!line.TotalPrice}" /> </apex:outputText> </b>
           </td>
        </tr>
        <apex:variable var="count" value="{!count+1}"/>
       </apex:repeat>
       <tr style="page-break-inside:avoid;"> 
           <td colspan="6" style="border-top:none;" >&nbsp; </td>
       </tr> 
        </table>
        
        <table width="100%" style="border-collapse: collapse;page-break-inside:avoid;page-break-after:auto;">
          <tr   >
             <td colspan="2" style="color:#9a0200;border:1px solid black;border-right:none;border-left:none;padding:5px;">{!Quote.Customer_Message__c}</td>
             <td colspan="2" align="right" style="border:1px solid black;border-right:none;border-left:none;"><b> Total:</b></td>
             <td align="right" style="border:1px solid black;border-left:none;border-right:none;"><b><apex:outputField value="{!Quote.TotalPrice}"/></b></td>
       
         </tr> 
        </table>
   
 </div>
 </body>    
</apex:page>