0

I have visualforce page that contains report card. This page have command button like Back to page and Print . I am using for Print command button

apex:commandLink value="Print" onclick="window.print();"

This is printing along with buttons. but i don't want to print command buttons after we done print. Can anyone please help to how to print page with only required data.

2
  • when you click print set some value and don't display the button. Feb 4, 2016 at 5:22
  • i am using this <apex:commandLink value="Print" onclick="window.print();"/>. In this how can we hide buttons Feb 4, 2016 at 5:23

4 Answers 4

1

Try this sample page

     <apex:page showheader="false" sidebar="false">
    <apex:form>
        <apex:commandlink styleClass="cButtons" value="Print" reRender="dummy" onclick="printMyPartialPage();"/>
        adfas<br/>
        asdfs<br/>
        asdfasdfasdfasdf<br/>
        
        asdfasdfasdfasdfasd <br/>
        
    </apex:form>
    <apex:includeScript value="https://code.jquery.com/jquery-2.2.0.min.js"/>
    
    <Script>
        function printMyPartialPage(){
            $('.cButtons').hide();
            window.print();    
        }
    </script>
</apex:page>
7
  • it is firing error "Unsupported attribute class in &lt;apex:commandLink&gt; in class" Feb 4, 2016 at 5:45
  • Use styleClass instead of class. Updated my answer Feb 4, 2016 at 5:46
  • ok now error is not firing, but when i click on Print link it not responding... it is redirecting to same page.. Feb 4, 2016 at 5:51
  • Did you check for console errors? Have you included jQuery in your page? I hope you know what I am talking about. Feb 4, 2016 at 5:59
  • I din't get you, But i checked in developer console errors... no errors in the logs. I'm Sorry for making you confuse.. Feb 4, 2016 at 6:11
0

This might be useful for you - https://developer.salesforce.com/blogs/developer-relations/2008/06/dynamically-cho.html.

You can dynamically render your page as PDF and use the 'chooserender' variable in the above link to hide your command buttons

1
  • This link is somewhat helping, but the print is not coming properly. some data missing. Thanks Ansuman Feb 4, 2016 at 7:48
0

You would have to place the content to print in a separate section say div. And use command button in a different section and use below code:

<div id="printDiv">
<apex:pageblock>
...
...Your Page content to print....
...
</apex:pageBlock>
</div>
<apex:commandLink onclick="myFunction('printDiv')" value="Print"/>

The JS function:

function myFunction(printDiv) { var printContent = document.getElementById(printDiv).innerHTML; var w = window.open(); w.document.write(printContent); w.print(); w.close(); }

0

enter image description here

enter image description here Use the below code to provide a print option of your entire VFpage

    <tr>    
        <td align="right"><a href="javascript:window.print();">Print</a></td>
    </tr>
1
  • this does not answer the question, the OP is specifically asking to print only specific data, not the whole page.
    – glls
    Mar 26, 2021 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .