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 VF Page

Hi All, 
I am using the following Script inside  a VF Page to print the VF Page without preview it. 
The page is rendered in the printer format but it Is also previewed in the backgroud (Screenshot below). i mean when  i click  on the button , The VF Page and the Printer page , the both are open.  I do not want to preview the VF Page. If i could  automatically send it to the printer  when the button is clicked without any preview that would be awesome. 

Here th starting of my page
<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>

User-added image
ANUTEJANUTEJ (Salesforce Developers) 
Hi Gibson,

>> https://developer.salesforce.com/forums/?id=906F0000000BLD8IAO

As mentioned in the above link can you try checking if this helps: "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>
"

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Girbson Bijou 8Girbson Bijou 8
HI Anutej, 
Here is my code, can you let me know where and how to insert it. 
<apex:page  readOnly="false"  action="{!updateDelivery}"  showHeader="false" sidebar="false"  applyHtmlTag="false"   standardStylesheets="false"  standardController="Delivery__c" extensions="DeliveryPageClass"  applyBodyTag="false" >    
    
    <head>
        <script type="text/javascript">
        window.onload=function(){
            window.print();
        };
        
        </script>
        <style>
            
        
            table {
            font-family: arial, sans-serif;
            border-collapse: collapse;
            width: 100%;
            }
            
            td, th {
            border: 1px solid rgb(83, 83, 85, 0.4);
            padding: 8px;
            line-height: 0.7em;
            }
            
            tr:nth-child(even) {
            background-color: 	rgba(0, 183, 255, 0.2);
            }
            
        </style>
    </head>

 
Dushyant SonwarDushyant Sonwar
Removing browser defaut print preview option is not possible. This is a mandatory step for all browsers to show the preview to ther user , what they actually are printing.