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
Kathryn Lee 10Kathryn Lee 10 

how to add print feature to visualforce page

I am still a very basic level when it comes to visualforce. I created a page that links to an external website (code below). I was wondering if there was a way to add in the print link that is found on Salesforce object pages. I know how to suppress the sidebar, but wasn't sure how to add "print" back in. 

<apex:page sidebar="false"> <script type="text/javascript" src="https://www.google.com/jsapi"></ script><script type="text/javascript">google.load("maps", "3", {other_params:"sensor=false"});</script><script language="javascript" src="//code.metalocator.com/index.php? option=com_locator&view=directory&layout=_javascript&framed=1&format=r aw&tmpl=component&no_html=1&Itemid=3627"></script> </apex:page>
 
Best Answer chosen by Kathryn Lee 10
kaustav goswamikaustav goswami
Place an image on a printer on the top right hand corner (or where ever you think is suitable). Then on click of that image call a javascript function in that function execute this statement - window.print() - this will open the print window or depending on end user browser setting print the page.
 
<apex:image .... onclick="printFunc();return false;" />

<script type="test/javascript">
    function printFunc(){
        window.print();
    }
</script>

Thanks,
Kaustav

All Answers

kaustav goswamikaustav goswami
Place an image on a printer on the top right hand corner (or where ever you think is suitable). Then on click of that image call a javascript function in that function execute this statement - window.print() - this will open the print window or depending on end user browser setting print the page.
 
<apex:image .... onclick="printFunc();return false;" />

<script type="test/javascript">
    function printFunc(){
        window.print();
    }
</script>

Thanks,
Kaustav
This was selected as the best answer
Kathryn Lee 10Kathryn Lee 10
Kaustav,

Thanks for the quick reply. That is exactly what I needed. 
Seemu Saikia 4xSeemu Saikia 4x
You can use it as follows : 
<table width="98%" border="0" cellpadding="0" cellspacing="0">
        <tr>    
            <td align="right"><a href="javascript:window.print();">Print</a></td>
        </tr>
  </table>