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 Razim 17Lukas Razim 17 

visualforce page header/footer

Hi. I found some articles how to generate header/footer in your pdf. However I cannot use renderas=pdf (as there are special characters in my language which are not generated properly, but it's just fine if I dont use renderas=pdf) and I would like to have footer and header generated on my pages to be printed later. It does work properly with the code below if I add renderas=pdf but like I said I cannot and when the page is generated without renderas=pdf, the footer text is placed right after the signature, not at the bottom of the page.
Can anyone tell me please where Im doing the mistake? Thank you very much
<apex:page standardController="Campaign" showHeader="false" applyBodyTag="false">

<head>
<style type="text/css" media="print">
@page {
@top-center {
content: element(header);
}
@bottom-left {
 content: element(footer);
}
}
 
div.header {
padding: 10px;
position: running(header);
}
div.footer {
display: block;
padding: 5px;
position: running(footer);
}
 
.pagenumber:before {
content: counter(page);
}
.pagecount:before {
content: counter(pages);
}
</style>
</head>


<apex:repeat value="{!Campaign.CampaignMembers}" var="line">
  
<div class="header"><div>My Header Text</div></div>

<div class="content">  
  
  <div style="page-break-after:always;">
  
  <apex:outputText value="{!line.Contact.Oslovujeme__c}," rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
  <apex:outputText value="{!Campaign.Hard_copy_invitation__c}" rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
  <apex:outputText value="Kind regards," rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
  <apex:outputText value="A-Team" rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
  
  <div class="footer"><div>My footer Text</div></div>
  
  </div>

 </div>  
          
  </apex:repeat>

</apex:page>
Sunil MadanaSunil Madana
Hello, i am not sure if you fixed the issue. Otherwise, you can use the below code.
<apex:page renderAs="pdf" applyBodyTag="false" standardController="Campaign">
    <head>
        <style type="text/css" media="print">
            @page { @top-center { content: element(header); } @bottom-left { content: element(footer); } }
            
            div.header { padding: 10px; position: running(header); margin: 0px; }
            
            div.footer { display: block; padding: 5px; position: running(footer); }
            
            .pagenumber:before { content: counter(page); }
            
            .pagecount:before { content: counter(pages); }
        </style>
    </head>
    
    <div class="header">
        <div>My Header Text</div>
    </div>
    
    <apex:repeat value="{!Campaign.CampaignMembers}" var="line">
        <div class="content">
            <div style="page-break-after:always;">
                <apex:outputText value="{!line.Contact.Oslovujeme__c}," rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
                <apex:outputText value="{!Campaign.Hard_copy_invitation__c}" rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
                <apex:outputText value="Kind regards," rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
                <apex:outputText value="A-Team" rendered="{!line.Status='Letter to Send'}" escape="false"/><br/>
            </div>
        </div>
    </apex:repeat>
    
	<div class="footer">
        <div>My footer Text</div>
    </div>    
</apex:page>
After trying the above code and if it worked, please mark this answer correct. Thanks.