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
Girbson Bijou 8Girbson Bijou 8 

Print Directely to printer

Hi All, 
I need to use a button to print a VF Page directely to a printer without preview it. My requirement is to autorized a document to be printed only one time. As solution, i use a print counter (custom field) which is incremented each time the print button is clicked.  the problem i have with that solution is when the user click the button, the page is rendered as PDF and the use is able to print it the number of time he want. 

Let me know how i can print without preview.

Thank you,
AnudeepAnudeep (Salesforce Developers) 
You would have to remove renderAs="pdf" option in your VF page and use window.print() function

Try the following code
 
<script type="text/javascript">
window.onload=function(){
   window.print();
};

</script>

Let me know if it helps. If it does, please mark this answer as Best. It may help others in the community

Thank You1
Girbson Bijou 8Girbson Bijou 8

Hi Anudeep, 
Thank you for replying.
the page is rendered in the format printer but the VF Is style diplayed in background. i mean when  i click  on the button , The VF Page and the Printer page , the both are open.

How can i open only the print page. 
here is the starting of my VF code
<apex:page readOnly="false"  action="{!updateDelivery}"  showHeader="false" sidebar="false"  applyHtmlTag="false"   standardStylesheets="false"  standardController="Delivery__c" extensions="DeliveryPageClass"  applyBodyTag="false" >    

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