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

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

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"/>

I thought it will execute only once


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> 

You can use post-processing tools such as this: PDFBox to strip the last page from a pdf. Perhaps a Heroku Rest service that accepts pdfs and returns the pdf - last page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.