Reply
Visitor
MILK
Posts: 6
0

HOW TO PRINT A PDF DOCUMENT BY PRESSING A BUTTON IN SALESFORCE DIRECTLY WITHOUT "PREVIEW"

BELOW IS MY CODE ON THE BUTTON:

 

{!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")}
var smid = '{!Sales_Memo__c.Id}';
var result = sforce.connection.query("select Id, No_of_Prints__c From Sales_Memo__c where Id = '{!Sales_Memo__c.Id}' limit 1");
var records = result.getArray("records");
if (records.length > 0) {
var record = records[0];
var i = record.No_of_Prints__c;
record.No_of_Prints__c = ++i;
var result = sforce.connection.update([record]);
if(result[0].getBoolean("success")) {
window.open("https://ap1.salesforce.com/apex/SMPDF_re?id="+smid);
document.location.reload();
}
else {
window.alert ("failed to update Sales Memo " + result[0]);
}
}
else {
window.alert ("No record found for Sales Memo Id : {!Sales_Memo__c.Id}" );
}

 

Regular Contributor
puru
Posts: 11
0

Re: HOW TO PRINT A PDF DOCUMENT BY PRESSING A BUTTON IN SALESFORCE DIRECTLY WITHOUT "PREVIEW&q

Hi,

 

Here you can simply call JavaScript print function to print document.

on successfull update you can call "window.print()" to print your document.

Or in better way you can call this window.print() function on onload event of javascript.

You can add this onload event in you "SMPDF_re" vf page.

 

 

Regards,

Purushottam

Purushottam Bhaigade Software Developer, Screen-Magic
purushottambhaigade@gmail.com | www.screen-magic.com

 

Facebook Twitter LinkedIn
Contact me: Skype purushottam8688

Visitor
MILK
Posts: 6
0

Re: HOW TO PRINT A PDF DOCUMENT BY PRESSING A BUTTON IN SALESFORCE DIRECTLY WITHOUT "PREVIEW&a

Thanks for your idea!

 

However, I dun know how to add the "window.print()" into my "SMPDF_re" vf page.

 

 

below is my code:

 

<apex:page standardController="Sales_Memo__c" tabStyle="Sales_Memo__c" extensions="SMPDF_reController" renderAs="pdf">

........................................

Regular Contributor
puru
Posts: 11
0

Re: HOW TO PRINT A PDF DOCUMENT BY PRESSING A BUTTON IN SALESFORCE DIRECTLY WITHOUT "PREVIEW&a

Hi,

 

You can add following code snippet into your visualforce page after <apex:page> tag

 

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

</script>

 

I hope it will help you.

 

Regards,

Purushottam

Purushottam Bhaigade Software Developer, Screen-Magic
purushottambhaigade@gmail.com | www.screen-magic.com

 

Facebook Twitter LinkedIn
Contact me: Skype purushottam8688

Visitor
MILK
Posts: 6
0

Re: HOW TO PRINT A PDF DOCUMENT BY PRESSING A BUTTON IN SALESFORCE DIRECTLY WITHOUT "PREVIEW&a

It seems not work.Below is my code in visualforce page:

 

<apex:page standardController="Sales_Memo__c" tabStyle="Sales_Memo__c" extensions="SMPDF_reController" renderAs="pdf" >

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

</script>





<head>
    <style type="text/css">
        
        body {
           
            font-family: Arial, Helvetica, sans-serif;
            color: #555;
            font-size:11px;
        }
        
        @page{
            size: 840px 1188px;
            margin-top:77.4 px;
            margin-bottom:48 px;
            margin-left: 13px;
            margin-right: 13px;
            
            
            @bottom-center{  
              content: element(footer)
            }
        }
        div.footer{
           
           position: running(footer);
        }
        .detailInformation{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 13px;
            color: #000;
            margin-left: 10px;
            font-weight: normal;                                            
        }
        td.detailInformation{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 13px;
            color: #000;
            margin-left: 10px;                                              
        }
        th.detailInformation{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 13px;
            color: #000;
            margin-left: 10px;                                              
        }
        
        
        .detailInformation1{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 13px;
            color: #000;
            font-weight: normal;
                                                    
        }
        td.detailInformation1{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 13px;
            color: #000;
                                                
        }
        th.detailInformation1{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 13px;
            color: #000;
                                            
        }
        .detailInformation3{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 11px;
            color: #000;
            font-weight: normal;
                                                    
        }
        
        .tabledetailInformation{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 13px;
            color: #000;
            margin-left: 10px;   
             text-align: right                                          
        }
        
        th.tabledetailInformation{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 13px;
            color: #000;
            margin-left: 10px;   
             text-align: right                                          
        }
        .detailInformationBold{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 24px;
            color: #000;
            font-weight: bold;                      
        }
        .itemLabel{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 13px;
            color: #333;
            font-weight: bold;
        }        
        .itemtable{
            border-left:1px solid #000;
            border-right:1px solid #000;
            border-top:none;
            border-bottom:1px solid #000;
                      
        }
        .itemtable td{
            border:none;
        }
        .remarktable{
            border:1px solid #000;
                      
        }
        .remarktable td{
            border:none;
        }
 
    </style>
</head>
<div class="footer">
<div>&nbsp;&nbsp;&nbsp;<apex:outputText value="{!SM.Sys_Store_Address__c}" />&nbsp;&nbsp;&nbsp;&nbsp;<apex:outputText value="{!SM.Sy_store_phone__c}" /></div>
</div>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td height="40" align="right">
            <apex:outputText value="{!SM.Sys_Reprint__c}" style="font-family: Arial, Helvetica, sans-serif;
                                                                 font-size: 18px;
                                                                 color: #000;
                                                                 margin-left: 10px;   "/>
        </td>
    </tr>
</table>

<table width="100%" height="180" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>
<table width="100%" height="180" border="0" cellpadding="2" cellspacing="0">
 <col width="18%"></col>
 <col width="15%"></col>
 <col width="11%"></col>
 <col width="22%"></col>
 <col width="17%"></col>
 <col width="17%"></col>
 <tbody>
  <tr>
    <th height="40" valign="Top" colspan="2" style="border-top:none;
                                                    border-right: 0.5px solid ;
                                                    border-bottom: 0.5px solid ;
                                                    border-left: none; ">
        &nbsp;&nbsp;<apex:outputText value="Customer Name:" styleClass="itemLabel" />&nbsp;&nbsp;&nbsp;&nbsp;
        <apex:outputText value="{!CustomerName}" styleClass="detailInformation"/>
    </th>
    <th height="40" valign="Top" colspan="2" style="border-top:none;
                                                    border-right: 0.5px solid ;
                                                    border-bottom: 0.5px solid ;
                                                    border-left: none; ">
        &nbsp;&nbsp;<apex:outputText value="Tel.:" styleClass="itemLabel"/>&nbsp;&nbsp;&nbsp;&nbsp;
        <apex:outputText value="{!PhoneCombine}" styleClass="detailInformation"/>
    </th>
    <th height="40" colspan="2" valign="Middle" style="border-top:none;
                                                    border-right: none;
                                                    border-bottom: 0.5px solid ;
                                                    border-left: none; ">
         &nbsp;&nbsp;<apex:outputText value="SALES MEMO" styleClass="detailInformationBold"/></th>
  </tr>
  <tr>
    <th height="96" valign="TOP" style="border-top:none;
                                                    border-right: none ;
                                                    border-bottom: 0.5px solid;
                                                    border-left: none; ">
        &nbsp;&nbsp;<apex:outputText value="Delivery Address:" styleClass="itemLabel"/>

        
    </th>
    <th height="96" colspan="3" valign="TOP" style="border-top:none;
                                                    border-right: 0.5px solid ;
                                                    border-bottom: 0.5px solid ;
                                                    border-left: none; ">
        
        <apex:outputText value="{!ShippingAddress}" styleClass="detailInformation1"/>
        
    </th>
    <th height="96" colspan="2" valign="TOP" style="border-top:none;
                                                    border-right: none;
                                                    border-bottom: 0.5px solid ;
                                                    border-left: none; ">
.......
......
......

                <td colspan="2" >

                    <apex:outputText value="I acknowledge and agree with Miele’s general terms & conditions attached." styleClass="itemLabel"/>

                </td>

            </tr>

        </table>

    </td>

   </tr>

</table>

 

</body>

 

 

 

 

</apex:page>
Regular Contributor
puru
Posts: 11
0

Re: HOW TO PRINT A PDF DOCUMENT BY PRESSING A BUTTON IN SALESFORCE DIRECTLY WITHOUT "PREVIEW&a

Hi,

 

Yes it will not work because you are trying to execute jscript on pdf page.

When we use renderAs="pdf" then that page is no more html so it will not execute any javascript.

 

What you can do is you can simply remove attribute renderAs="pdf" from the page tag and your script will run.