naveen
naveen

Reputation: 159

How to apply page break after each element in repeat in visualforce when rendering as pdf

I'm trying to render a VF page as pdf. The Vf page will iterate over a list account records with repeat tag. For each element in repeat tag I want apply a page break. The below code working but is has a issue. The below code showing empty pdf after last element. How to avoid showing empty pdf page after last page.

<apex:page standardController="Account" recordSetVar="accnts" sidebar="false" renderAs="pdf">
    <apex:pageBlock title="My Content" > 
        <apex:repeat value="{!accnts}" var="acc" rows="3" first="5" >   
            <div style="page-break-after:always">          
                <apex:outputText style="color: #f60; font-weight: bold;font-size:30px;" value="{!acc.Name}" >    
                </apex:outputText>
            </div>
        </apex:repeat>
    </apex:pageBlock>
</apex:page>

Thanks in advance.

Regards,

​Naveen.​

Upvotes: 0

Views: 4364

Answers (1)

TechingCrewMatt
TechingCrewMatt

Reputation: 526

Inside your repeating element, you can use inline-styling as Salesforce suggests:

<apex:repeat value="{!account.contacts}" var="c">
   <div class="breakPageAfter" style="page-break-after:always;">
        <span>{!c.name}</span>
   </div>
</apex:repeat>

Alternatively you can add the styling to your CSS markup:

<style>
   .breakPageAfter{
      page-break-after:always;
   }
</style

Upvotes: 2

Related Questions