You need to sign in to do that
Don't have an account?
Leafen Sandy
Script not getting executed if the page is redirected from pagereference in a different controller
Hi,
I have a vf page which would contain a script that executes on load and displays some content after loading and this works fine.
But if I call this page using pagereference in a different controller and if I try to convert the page as a pdf using getcontentaspdf() it doesnt executes the action inside the script and so pdf doesnt has the content from the script.
Below is exactly a sample of what I tried,
Page1: mypdfpage
controller :
So from the above code snippet,
If I try to load the vfpage I get a image and para giving src of the image which is obtained from the script.
But if I try to call the page from my apex class pdfgenerator, and convert it as pdf using EncodingUtil.base64Encode(blob), later when I try to decode and view as pdf, I get only the image not its src.
So I guess my script is not executed when I call the page from controller.
Would like to know on how to execute the script in the page from a controller.
Thanks in Advance,
Leafen.
I have a vf page which would contain a script that executes on load and displays some content after loading and this works fine.
But if I call this page using pagereference in a different controller and if I try to convert the page as a pdf using getcontentaspdf() it doesnt executes the action inside the script and so pdf doesnt has the content from the script.
Below is exactly a sample of what I tried,
Page1: mypdfpage
<apex:page> <img id="myImg" src="img_pulpit.jpg" alt="The Pulpit Rock" width="304" height="228" /> <p id="demo"></p> <script> window.onload = function() { alert('tset'); var x = document.getElementById("myImg").src; document.getElementById("demo").innerHTML = x; }; </script> </apex:page>
controller :
global class pdfgenerator{ public pdfgenerator(){ PageReference pageRef = Page.mypdfpage; pageRef.setRedirect(true); Blob pageContent = pageRef.getContentaspdf(); String stringContent = EncodingUtil.base64Encode(pageContent); system.debug('String Content = ' + stringContent); } }
So from the above code snippet,
If I try to load the vfpage I get a image and para giving src of the image which is obtained from the script.
But if I try to call the page from my apex class pdfgenerator, and convert it as pdf using EncodingUtil.base64Encode(blob), later when I try to decode and view as pdf, I get only the image not its src.
So I guess my script is not executed when I call the page from controller.
Would like to know on how to execute the script in the page from a controller.
Thanks in Advance,
Leafen.