+ Start a Discussion
Aruna VasahanAruna Vasahan 

Add header to all the pages when printing a visualforce page

I want to print dynamic header in all the pages of a visualforce paage rendered document. By using CSS styles I am able to get header in visualforce page when rendered as pdf but header is not coming when printed using window.print().
Here is my code:
<apex:page controller="Template" showHeader="false" standardStylesheets="false"  sidebar="false" action="{!renderTemplate}" 
           renderAs="{!chooserender}" applyHtmlTag="false" applyBodyTag="false" >
    <html>
        <head>
            <style type="text/css" media="print">
                @page {
                    padding-top: 40px;
                    @top-center {
                        content: element(header);
                    }
                }
                div.header {
                    padding :10px;
                    position: running(header);
                }
            </style>
        </head>
        <body>
            <apex:form id="renderContentForm">
                <div class="header">

                    <apex:outputText id="htmlHeaddddd" value="{!htmlHead}" >   </apex:outputText> 
                </div>
                <div id='content'>

                    <apex:outputText id="htmlText" value="{!htmlCode}" ></apex:outputText>  
                </div>
            </apex:form>
        </body>
    </html>
</apex:page>
In render as="Pdf" I am getting "header"n all pages but when tried to "print" I am not getting the "header". Do anyone know how to do this?
 
Dushyant SonwarDushyant Sonwar
I don't think this issue is related to code as you said that you are clicking standard print button when pdf is generated.
Please review the below article for this issue.
https://social.technet.microsoft.com/Forums/Lync/en-US/cf37b918-d683-4e9a-bbb0-d5e06c14fbcd/i-cant-see-a-header-while-in-print-preview-nor-print-it-when-in-word-2010-but-i-can-in-word-2007?forum=word
Aruna VasahanAruna Vasahan
@Dushyant, that page doen't have answer for me. I was not able to find the options mentioned in that page in my printer settings. I want something in my code that makes my code to work.