How to print Visualforce page without header and footer int eh Print preview?

How to print Visualforce page without header and footer int eh Print preview?

Sample Code:

Visualforce page:


<apex:page controller=”Sample” showHeader=”false”>
<head>
<style type=”text/css”>


@page{
        size: auto A4 landscape;
        margin: 3mm;
     }


</style>
</head>
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value=”{!listAcct}” var=”a”>
            <apex:column value=”{!a.Id}”/>
            <apex:column value=”{!a.Name}”/>
        </apex:pageBlockTable>
        <apex:pageBlockButtons >
            <apex:commandButton value=”Print” onclick=”window.print()”/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form> 
</apex:page>


Apex Class:

public class Sample {
    public List < Account > listAcct {get;set;}
    public Sample() {
        listAcct = [ SELECT Id, Name FROM Account ];
    } 
}

Output:


Leave a Reply