You need to sign in to do that
Don't have an account?
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}" );
}
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
Contact me: purushottam8688
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">
........................................
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
Contact me: purushottam8688
It seems not work.Below is my code in visualforce page:
<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>
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.
Do we have any workaround for this?
I got the similar requirement. Please let me kow if anyone got anything.
Thanks,
Anil