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
sgoldberRHsgoldberRH 

renderAs PDF ignoring JavaScript

 I have a visual force page which needs to be rendered as a PDF, but when I set renderAs = "PDF"  it ignores my Javascript entirley. I can't even do a document.write('test');   My issue is that the field labels in the PDF I am rendering need to be dynamic based on the users language. I have written a class to do this for me based on the API field name, but when I try and call it in this page I get nothing.  Anyone have any suggestions on how to dynamically pass field labels to a VF page that will be rendered as a pdf? 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Ron HessRon Hess

using the label expression is correct ( and very elegant) since no extra round trips are created.

 

Section heading labels ? no, at least i don't think so. 

 

you would have to store these into a custom label and display it on the page using $Label.mysection 

 

https://tapp0.salesforce.com/help/doc/user_ed.jsp?section=help&target=cl_about.htm&loc=help&hash=topic-title

All Answers

Ron HessRon Hess

there is no browser when you  render as PDF, so no javascript will run.

 

if you expose the labels using $Label feature, you can use those labels in your page.

Siddhesh KabeSiddhesh Kabe

You can also use OutputField to print the field and value. Use action methods instead of javascript to select the language.

 

RenderAs='Pdf' is a SFDC feature so achieve your Business Logic with SFDC features as far as possible.

 

If you have to use JavaScript...

 

Put the code in some S-control or other VF and make it redirect to page using RenderAs PDF passing the option as URL parameters.

You can fetch the parameters in constructor and render things accordingly.

 

Hope it helps.

 

P.s. If you can put a code snippet here, i believe you can get more information.

sgoldberRHsgoldberRH

Siddhesh,

 

Thanks for the help... I am still a little confused ... I am very new to VF.  Here is an example of what I am trying to do. 

//getting the field label var mdfFundsAvailQ1 = sforce.apex.execute("getFieldLabels","bpGetLabel", {fieldName:"MDF_Funds_Available_Q1__c"}); // the page <apex:pageBlock > <apex:pageBlockSection columns="4"> <b><script> document.write(mdfFundsAvailQ1</script></b> <apex:outputText value="{!AllocatedBudget1}"/>

 

 

Maybe I am missing something, but I don't see a way to get the field label from a standard SFDC feature... Thanks again for your help.


 

Ron HessRon Hess

there is a feature designed for labels, please try to use this instead of calling Apex from javascript.

 

 

 

$Label

Description A global merge field type to use when referencing a custom label in a Visualforce page.
Use Use this expression in a Visualforce page to access a custom label. When the application server constructs the page to be presented to the end-user’s browser, the value returned depends upon the language setting of the contextual user. The value returned is one of the following, in order of precedence:
  1. the local translation's text
  2. the packaged translation's text
  3. the master label's text
Example
<apex:page>
<apex:pageMessage severity="info"
strength="1"
summary="{!$Label.firstrun_helptext}"
/>
</apex:page>

 

sgoldberRHsgoldberRH

Ron,

 

Thanks for the info.  I am currently using this now: 

{!$ObjectType.SFDC_Channel_Account_Plan__c.Fields.Partner_Name__c.label}

 

will that function differently?

 

 

 

 

Ron HessRon Hess
that should work, does it?
sgoldberRHsgoldberRH
Yeah it does.... I just wasn't sure if it wasn't the optimal way to do it.  I am very new to this so I apprecitate all the help.  Is there a way to grab section heading labels?
Ron HessRon Hess

using the label expression is correct ( and very elegant) since no extra round trips are created.

 

Section heading labels ? no, at least i don't think so. 

 

you would have to store these into a custom label and display it on the page using $Label.mysection 

 

https://tapp0.salesforce.com/help/doc/user_ed.jsp?section=help&target=cl_about.htm&loc=help&hash=topic-title

This was selected as the best answer
sgoldberRHsgoldberRH
Thanks Ron, that was very helpful.
JaksonJakson

hey ron,

 

Can you put the code snippet here. unable to see the link, maybe its broken