I have a vf page with a custom iframe url. This page also has a button which on click captures the screenshot and mails it to the given email id.

Below is my vf page and controller:

VF Page:

<apex:page  showheader="false" sidebar="false" controller="sendEmailWithImage">
    <apex:form id="frm">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/>
          <button onclick="callActionFunction()">SendEmail</button>
    <apex:actionFunction action="{!sendEmail}" name="sendEmailAF" rerender="frm">
        <apex:param assignTo="{!strImageBlob}" name="imageBlob" value=""/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
    <script type="text/javascript">
        window.onload = function(){
                useCORS: true,
                onrendered: function(canvas) 
                    document.getElementById("mapDiv").style.display = 'none';
        function callActionFunction()
        <apex:iframe src="https://app.powerbi.com/view?r=<custom-URL>" height="540" width="100%" frameborder="0">



public class sendEmailWithImage 
    public string strImageBlob {get;set;}
    public void sendEmail()
        Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
        List<String> lstString = new List<String>();
        mail.setToAddresses(new String[]{'testemail@gmail.com'});
        mail.setSubject('Email found');
        Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
        attach.Body = EncodingUtil.base64Decode(strImageBlob.replaceFirst('data:image/png;base64,',''));
        mail.setHtmlBody('Please find the attached Image');
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

Now, when i click on the send email button, I am getting the email but with the blank/plain screen. Can anyone please suggest the changes in the above code so that i can email the proper screenshot on button click.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.