[SalesForce] Remove Last Page from the PDF

I have created PDF of Multipage, where in VF page I am using

<apex:repeat .......>
 ///////// some code
  <div style="page-break-before:always;"/>
</apex:repeat>

But it adds a Blank page in the end each time, how can I avoid that one

I am trying this one, where flag=True in constructor. Note : I do not have any method written in Controller to change flags value.

<apex:pageBlockSection rendered="{!flag}">
    <div style="page-break-after:always;"/>
    <apex:param assignTo="{!flag}" value="False"/>
</apex:pageBlockSection>

I thought it will execute only once

Best Answer

I've handled this directly as part of my Apex code by using some CSS tricks. Try this out.

<apex:variable var="cnt" value="{!0}" />    
<apex:repeat value="{!cases}" var="cse"> 
      <!-- apex:OutputText value="{!cnt}"/ -->
     <div style="{!if(cnt < 1, 'page-break-before:avoid;','page-break-before:always;')}">
     <apex:variable var="cnt" value="{!cnt+1}"/> .... .... </div> 
 </apex:repeat>