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
Lukas R.Lukas R. 

Page break after

Hi,
Im trying to generate letter using the VF page for campaign members who are contacts and have status 'Letter to Send' (see code below). It is generated properly however when I set the result page to print, it includes the blank pages for all campaign members who dont have this status as well and I would like to avoid this. In other words if I have 40 campaign members and only 2 of them with status 'Letter to Send' I need just two pages to be sent for printing the hard copy but it generates 38 more blank pages as result. Im not really good at coding, can somebody help me out? Many thanks
<apex:page standardController="Campaign" showHeader="false" applyBodyTag="false">

  <apex:repeat value="{!Campaign.CampaignMembers}" var="line">
 
  <div style="page-break-after:always;">
  
  <apex:outputText value="{!line.contact.Osloveni__c} {!line.contact.Vokativ__c}," rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
  <apex:outputText value="{!Campaign.Letter__c}" rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
  <apex:outputText value="S pozdravem," rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
  <apex:outputText value="LR" rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
  
  </div>
  

  
  </apex:repeat>

</apex:page>

 
Best Answer chosen by Lukas R.
Rajiv Penagonda 12Rajiv Penagonda 12
Lukas, see if the following works for you:
 
<apex:page standardController="Campaign" showHeader="false" applyBodyTag="false">
	<apex:repeat value="{!Campaign.CampaignMembers}" var="line">
		<apex:outputPanel layout="block" style="page-break-after:always;" rendered="{!line.Status='Letter to Send'}">
			<apex:outputText value="{!line.contact.Osloveni__c} {!line.contact.Vokativ__c}," escape="false"/><br/>
			<apex:outputText value="{!Campaign.Letter__c}" escape="false"/><br/>
			<apex:outputText value="S pozdravem," escape="false"/><br/>
			<apex:outputText value="LR" escape="false"/><br/>
		</apex:outputPanel>
	</apex:repeat>
</apex:page>
What I did was to remove the rendered clause from within the outputText and put it at the parent div level. So that the div is not rendered if the Status='Letter To Send' criteria is met.

All Answers

Rajiv Penagonda 12Rajiv Penagonda 12
Lukas, see if the following works for you:
 
<apex:page standardController="Campaign" showHeader="false" applyBodyTag="false">
	<apex:repeat value="{!Campaign.CampaignMembers}" var="line">
		<apex:outputPanel layout="block" style="page-break-after:always;" rendered="{!line.Status='Letter to Send'}">
			<apex:outputText value="{!line.contact.Osloveni__c} {!line.contact.Vokativ__c}," escape="false"/><br/>
			<apex:outputText value="{!Campaign.Letter__c}" escape="false"/><br/>
			<apex:outputText value="S pozdravem," escape="false"/><br/>
			<apex:outputText value="LR" escape="false"/><br/>
		</apex:outputPanel>
	</apex:repeat>
</apex:page>
What I did was to remove the rendered clause from within the outputText and put it at the parent div level. So that the div is not rendered if the Status='Letter To Send' criteria is met.
This was selected as the best answer
Lukas R.Lukas R.
Thanks Rajiv, works perfectly!